- Home /
Destroy specific Objects
I want to destroy an object when the health goes down below 0. Now my problem is I do not have a unique id so if I destroy the object by its tag it destroys all the objects with that tag as expected. I'm trying to use GUID to generate a unique ID, but am running into difficulties.
Firstly does GUID have to be a string?
public int id;
id = System.Guid.NewGuid();
Secondly how would I reference the object with that specific id to destroy it?
If you want to destroy your player, just attach a script like this to your character;
var health : float;
function Update()
{
if(health < 1)
{
Destroy(gameObject);
}
}
Answer by ZDS Alpha · Mar 29, 2014 at 03:58 PM
I think you should use object.GetHashCode() as unique id.
Answer by ava4414 · Mar 29, 2014 at 05:20 PM
It could be easier than making it every frame ask for its health, how do you reduce the objects health? because if you shoot or hit them you can obtain its game object and then destroy it
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Right way of controlling objects in Scene? 1 Answer
Destroy is not working with moving objects 1 Answer
Error destroying player over network 1 Answer