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

missing gameobject ≠ Null?

$
0
0
I made a script not too long ago, and it's supposed to detect if the variable 'target' is empty. When the object is destroyed, however, it says missing gameobject, and null no longer works. Can anyone tell me how to detect a missing gameobject? Here is the script: (asterisks where this part of the script is) var ifenemy : boolean; var Health : int; var Deadreplace : Transform; var target : Transform; //the enemy's target var tarpos : Vector3; var moveSpeed = 50; //move speed var rotationSpeed = 3; //speed of turning var thispos : Vector3; var inrange = false; var myTransform : Transform; //current transform data of this enemy function Awake() { myTransform = transform; //cache transform data for easy access/preformance } function Start() { Health = 100; } **function Update () { if(ifenemy == false){ target = GameObject.FindWithTag("Enemy").transform; //target the player } if(ifenemy == true){ target = GameObject.FindWithTag("GoodGuy").transform; //target the player } if(target != null){ print("working"); inrange = false; shootobj.GetComponent(AAShoot).canshoot = false; }** tarpos = target.position; thispos = transform.position; if(Vector3.Distance (thispos, tarpos) < 175){ inrange = true; shootobj.GetComponent(AAShoot).canshoot = true; myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime); //move towards the player myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime; } if(Vector3.Distance (thispos, tarpos) > 175){ inrange = false; shootobj.GetComponent(AAShoot).canshoot = false; } } function OnCollisionEnter (collision:Collision) { if (collision.gameObject.tag == "Damage") { Health -= 20; } }

Viewing all articles
Browse latest Browse all 7934

Trending Articles



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