Quantcast
Channel: Questions in topic: "help me"
Viewing all articles
Browse latest Browse all 115

Beginner please help. NullReferenceException: Object reference not set to an instance of an object

$
0
0
I'm new at this whole coding thing so I don't know what is wrong here I'm making a simple space shooter game and this is the part where the player life suppose to subtract every time the astriod hit the player here is my code: //Inspector variables var astroidSpeed : float = 10.0; var explosion : Transform; //Private Variable // Game loop function Update () { transform.Translate(Vector3.down*astroidSpeed*Time.deltaTime); // vector3.down = move object down on y axis // make astriod re appear at the top when it hit the bottom if(transform.position.y <= -10) { // reset enermy position transform.position.y = 0; transform.position.x = Random.Range(-10.0,10.0); } } function OnTriggerEnter (other : Collider) { if(other.gameObject.tag == "Player") { other.GetComponent("script player").lives -= 1; // get component to get component of other source Instantiate(explosion,transform.position,transform.rotation); // Reset enemy position other.transform.position.y = 10.0; other.transform.position.x = Random.Range(-10,10); } } it seem that the code it correct because unity let me run it but instead of subtracting player life i get this error code on the console instead. can someone tell me why?

Viewing all articles
Browse latest Browse all 115

Trending Articles



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