- Home /
hit.gameObject.tag
ok im using hit tags and the first one works but the second one just freezes so if i tag the sheep as "Bunny" they burst in to a red paritcal cloud but the sheep dont un less I use the Bunny tag but ....well I need more blood for the sheep! so I want to run a bigger partial explosion.
var particle : GameObject; var particleSheep : GameObject;
function OnControllerColliderHit( hit: ControllerColliderHit) { Debug.Log("hit Call"); if(hit.gameObject.tag == "Bunny") { Debug.Log("Bunny hit"); // create the instance of the prefab var clonedParticle : GameObject = Instantiate(particle, transform.position, transform.rotation);
clonedParticle.particleEmitter.emit = true; // tell it to emit
Destroy(clonedParticle, 4); //destroy the particle in 4 seconds
Destroy(hit.gameObject);
}
else if(hit.gameObject.tag == "Sheep") {
Debug.Log("Sheep hit");
// create the instance of the prefab
var clonedParticleSheep : GameObject = Instantiate(particleSheep,
transform.position,
transform.rotation);
clonedParticleSheep.particleEmitter.emit = true; // tell it to emit
Destroy(clonedParticleSheep, 4);//destroy the particle in 4 seconds
Destroy(hit.gameObject);
}
}
Answer by Atnas1010 · Nov 03, 2010 at 07:08 PM
Since you say it works when you tag the sheep "Bunny", the colliders must be set up properly. The only thing I can see that could be wrong would be that you have not tagged your sheep, "Sheep" (with a capital S) since that is what you compare the tag to.
If that doesn't solve the problem, then try adding an "else" after your sheep's "if", such as this
else
Debug.Log(hit.gameObject.tag);
And check your console, to see if it gets printed (and what it prints)
@Atnas - This doesn't actually tell the op what's happening. You should be clear in telling them that the only reason you see that the if(hit.gameObject.tag == "Sheep") would fail is if they were not properly tagged "Sheep".
I edited my answer. It might not be the same standard as yours, but I hope it is acceptable
Answer by skovacs1 · Nov 04, 2010 at 05:03 PM
There are only 2 reasons that I see that would cause your Debug("Sheep Hit") not to happen:
- The sheep are not properly tagged Sheep
- The sheep are not generating an OnControllerColliderHit
To address number 1. please verify that all instances of your sheep are properly tagged exactly Sheep with the exact case and spelling as you are checking for in your if statement.
To address number 2. please verify that your sheep have colliders that are setup properly. It seems that since you are colliding with your bunnies that your character controller capsule and movement must be setup correctly, but all the same, please ensure that neither of these is preventing collisions somehow. Also, please make sure that your sheep are on an appropriate layer for which Physics interaction with the layer the CharacterController is on has not been disabled.
If your Debug is printing, please rephrase the question to describe what exactly is not happening.
Your answer
Follow this Question
Related Questions
How does my raycast work? 1 Answer
Are tag settings passed down from Game Object parent to mesh child? 1 Answer
Accessing all GameObjects with a certain tag 1 Answer
Trouble editing tags 1 Answer