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

Could someone fix this error. "object not set to reference of an object"

$
0
0
I think I messed up the syntax or something. The code only works if it is the last thing in the update function. If I write code below it, it seems to not run it. Unity says the error is on line 33 where I check if the tag associated with the collision has the tag "player". public class EnemysProjectile : MonoBehaviour { public float speed; public float lifetime; public float distance; public LayerMask whatIsSolid; public float damage; public LayerMask whatIsPlayer; void Start() { Invoke("DestroyProjectile", lifetime); } void Update() { transform.Translate(Vector3.right * speed * Time.deltaTime); RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, transform.up, distance, whatIsSolid); RaycastHit2D ifHitPlayer = Physics2D.Raycast(transform.position, transform.up, distance, whatIsPlayer); if (hitInfo.collider != null && hitInfo.collider.CompareTag("Enemy") == false) { DestroyProjectile(); } if (ifHitPlayer.collider.CompareTag("Player") == true) { ifHitPlayer.collider.GetComponent().DamageToPlayer(damage); DestroyProjectile(); } } void DestroyProjectile() { Destroy(gameObject); } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>