Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

Keep getting the NullReferenceException Error and dont know whats wrong.

$
0
0
public class Projectile : MonoBehaviour { public float speed; public float lifeTime; public float distance; public LayerMask whatIsSolid; public int damage; private void Start() => Invoke("DestroyProjectile", lifeTime); private void Update() { transform.Translate(Vector2.right * speed * Time.deltaTime); RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, transform.right, distance, whatIsSolid); if (hitInfo.collider.CompareTag("Enemy")) { hitInfo.collider.GetComponent().takeDamage(damage); } DestroyProjectile(); } void DestroyProjectile () { Destroy(gameObject); } } Thats the code, and I get the error every-time I shoot.

Viewing all articles
Browse latest Browse all 2891

Trending Articles