Keep coming back withing an error in my script when I try to shoot. the problem is coming from line 12 , but I’m not sure what is happening. Here’s my script:
using UnityEngine;
using System.Collections;
public class Shoot : MonoBehaviour {
public KeyCode shoot;
// Use this for initialization
void Update () {
if (Input.GetKey (shoot)) {
Vector3 sp = Camera.main.WorldToScreenPoint(transform.position);
Vector3 dir = (Input.mousePosition - sp).normalized;
rigidbody2D.AddForce (dir * 500);
}
}
void OnTriggerEnter2D(Collider2D other) {
if (other.gameObject.name == "enemy") {
Destroy (other.gameObject);
}
if (other.gameObject.name == "player") {
Destroy (this.gameObject);
}
}
}