hey guys im trying to shoot with simple code i have 2 C# Classes one for Player movements and one for Bullet
this is Bullet Collision Class
void Start () {
source.clip = clip;
bullet = GetComponent<GameObject>();
rb = GetComponent<Rigidbody2D>();
bulletPos = player.position;
}
// Update is called once per frame
private void OnTriggerEnter2D(Collider2D wallCol)
{
if (wallCol.gameObject.tag == "Wall")
{
Debug.Log("Wall Hited!");
source.Play();
Destroy(bulletPrefab,clip.length);
if (bullet == null)
Instantiate(bulletPrefab, bulletPos, Quaternion.identity);
}
}
public void shoot()
{
rb.velocity = rb.transform.right * bulletSpeed;
}
this is Player Movement Class:
void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse0) && haveGlock == true)
{
bc.shoot();
AudioSource.PlayOneShot(GlockClip);
}
}
i did use shoot method on another class and when the method called its show me the object reference not set to instance of the object. also i drag and drop objects in required public variables in unity but why its not gonna work?
sorry for my bad English guys.