Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

missing object woe beginner

$
0
0
MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. Here, I want to make explosion but it throws such exception Before destroying object. here is my code: var shotSound: AudioClip; // drag a shot sound here, if any // the PickupController component of the 'PickupSpawnPoints' GameObject private var pickupController:PickupController; public var explosion : Transform; function Update(){ if (Input.GetKey(KeyCode.Space)) { Shoot(); } } function Shoot(){ if (shotSound) audio.PlayOneShot(shotSound); // play the shot sound var hit: RaycastHit; var ray = Camera.main.ScreenPointToRay (Input.mousePosition); if (Physics.Raycast (ray ,hit ,200)) { Debug.DrawRay (ray.origin, ray.direction * 10, Color.yellow); var pickupSpawnPoints:GameObject = hit.collider.gameObject; var clone : Transform; if(pickupSpawnPoints.tag == "Pickup") { clone = Instantiate(explosion,pickupSpawnPoints.transform.position, transform.rotation); Destroy(clone.gameObject); } } } I am currently learning unity. Please help me to solve this error . Thanx for ur help in advance,..

Viewing all articles
Browse latest Browse all 171066

Trending Articles



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