I’m pretty new to Unity, so please bare with me. I have an invulnerable monster that attacks the player and allies. So I use FindGameObjectsWithTag to chase the player group.
like so:
var localEnemies : GameObject[];
localEnemies = GameObject.FindGameObjectsWithTag("opponents");
I think this is pretty standard and works without problem. Just to test the code if NPCs are hit they are destroyed and if the player is hit a game over scene is loaded. How can I get the player object recognized outside the tag used for tracking position? Here is the code I’m working with. -
function OnCollisionEnter(collision : Collision)
{
var thing : GameObject = collision.gameObject;
if(thing.tag == "opponents" || thing.tag == "trap")
{
if(thing.tag == "opponent" && thing == GameObject.Find("Player"))
{
status = false;
animation.Play("attackMajor");
Instantiate(small_flame, thing.transform.position, thing.transform.rotation);
Application.LoadLevel("GameOver");
}
else if(thing.tag == "opponents" && thing != player)
{
status = false;
animation.Play("attackMajor");
Instantiate(small_flame, thing.transform.position, thing.transform.rotation);
yield WaitForSeconds(3);
Destroy(thing);
}
else if(thing.tag == "trap")
{
status = false;
animation.Play("rage");
yield WaitForSeconds(3);
Instantiate(small_flame, thing.transform.position, thing.transform.rotation);
Destroy(thing);
}
speed = 1;
status = true;
}
}
Any help would be really appreciated!
oh geez I'm such a dork there is a typo in the tag of the first if statement "opponent" should be "opponents"! AAARRGH :)
– Napalm6b