public void Dead()
{
Destroy(gameObject);
DisplayHealth();
}
When my mob dies i want to spawn my “Chest prefab” on its position.
Could You help me to do this ?
public void Dead()
{
Destroy(gameObject);
DisplayHealth();
}
When my mob dies i want to spawn my “Chest prefab” on its position.
Could You help me to do this ?
Use Instantiate to spawn the chest at the position you want:
var ChestPrefab : Transform;
Instantiate(ChestPrefab, transform.position, transform.rotation);
Make sure to add this line before destroying the script otherwise it might not work…
And make sure to assign the ChestPrefab variable in the inspector window.
P.s: This is in javascript but should be easy to change
You can write like this:
public void Dead() { Instantiate(chestprefab,transform.position,Quaternion.identity); Destroy(gameObject); DisplayHealth(); }
what i am trying to say is this: instantiate chest prefab right before you destroy gameobject
Is it in c#? Heres a very short script in javascript :
var chestPrefab : GameObject; //drag the prefab into this variable in the inspector window of the editor
function Dead(){
DisplayHealth();
Instantiate(chestPrefab, transform.position, transform.rotation);
Destroy(gameObject); //die/destroy yourself after doing all the things that are supposed to be done, you cant die first and then call the DisplayHealth function
}
I Hope this helps!
Its working :}
Thank u so much guys .
Its working ;]
Thank You so much guys .