Hello friends I am new to Unity. I am trying to make a small shooter game but I am facing a probelm.This is my script
and I want to use “.name” instead of “.tag”
But this is not working …Please help me…:(![]()
Hello friends I am new to Unity. I am trying to make a small shooter game but I am facing a probelm.This is my script
and I want to use “.name” instead of “.tag”
But this is not working …Please help me…:(![]()
Try using this,
function OnTriggerEnter (col : Collider){
if(col.transform.name == "Enemy"){
Destroy(gameObject);
}
EDIT: Should mention I haven’t tested this, but the part I changed should work.
.name is a property of Object, not Transform. It would work with Transform, only because it inherits .name from Object. In other words, there’s no reason to use Transform.name instead of GameObject.name. Better yet, you can just use “col.name”, since Collider.name also inherits from Object.
As for the question, do basic debugging like “print (col.name);” to see what the name actually is. I’d guess it prints “Enemy (Clone)”.
–Eric
Make sure you did attached the script and make sure your collider is set to isTrigger. Your codes is fine except one missing “}” at the back. And make sure you Enemy is spelled correctly. ![]()
Thanks Eric…now it is working…