I am making the shoot em up game. My idea is that Character can equip the guns from inventory, and they can shoot the bullet from weapon.
I think I should make array, and put the weapons. If weapon is equipped (bool true), player script calls the gameobject. However I have error…
is it better way to use List? I do not know how to start List in script… no idea.
error is
Error CS0176: Static member `WeaponList.bullets’ cannot be accessed with an instance reference, qualify it with a type name instead (CS0176) (Assembly-CSharp)
public class WeaponList : MonoBehaviour {
public static GameObejct[] bullets;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
public class PlayerController : MonoBehaviour {
[Header("Bullet")]
public Transform firePoint;
public static GameObject currentBullet;
public float fireRate = 1f;
private float fireCountDown = 0f;
public WeaponList WL;
// Use this for initialization
void Start () {
myRG = GetComponent<Rigidbody2D> ();
WL = FindObjectOfType<WeaponList> ();
}
public void Shoot() {
currentBullet = WL.bullets[1]; // This line has error!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
GameObject bulletGo = (GameObject)Instantiate (currentBullet, firePoint.position, firePoint.rotation);
BasicBullet bullet = bulletGo.GetComponent<BasicBullet> ();
}
}