- Home /
IT WORKS NOW I PUT THE PREFAB IN THE SCENE -___- SORRY
Wont let me instantiate gameobject when i destroy it?
Hi :) , i am trying to add a spawner , so when i press escape it comes up with a button that i can spawn zombies in , it works fine , but after i destroy it and click the spawn button again it doesn't let me spawn a zombie? my zombie is a prefab and it has a set spawn location . i HAVE to be able to destroy it
what do i have to do ??
MissingReferenceException: The object of type 'GameObject' 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.
if( GUI.Button(new Rect(10,150,150,50),"Spawn Zombie") ){
Instantiate(ZombieObject, ZombieSpawn.transform.position, Quaternion.identity);
}
YES i have done lots of research on this and all the other questions are not helping at all , they all have to do with timers and non of them are being destroyed . Please help me i am very stuck
Where is the script you use to destroy your zombie
If your Zombie is saved as a prefab and you have dragged that prefab into the inspector as a public variable you should have no problem instantiating multiple zombies.
Can you be a little bit more specific in your question? Don't use the word "it" so much haha
If your ZombieSpawn is a real prefab (i.e. it does not exist in the scene), then you should not have this problem. It appears you are using a scene item in your Instantiate().
http://docs.unity3d.com/Documentation/$$anonymous$$anual/Prefabs.html
i just realised how much i used it lol , ok ill give you the destroy script`var $$anonymous$$axHealth : int = 100;
var CurrentHealth : int = 0;
var Other : GameObject;
function Start () {
CurrentHealth = $$anonymous$$axHealth;
}
function ApplyDamage (Damage : float) {
if(CurrentHealth < 0){
return;
}
CurrentHealth -= Damage;
if(CurrentHealth == 0){
$$anonymous$$oneyScript.Current$$anonymous$$oney += 50;
Destroy( gameObject );
}
}`
Follow this Question
Related Questions
Spawning unique prefabs at different transform posititions 0 Answers
Place object randomly at any predefined spawn point 1 Answer
How to move a prefab to a gameobject position? 1 Answer
how do i know where my instantiated object came from? 2 Answers
Getting instance of an sub object rather than the original's subobject 0 Answers