sid4
November 27, 2016, 12:25pm
1
i want this gameobject to trigger if 2 or 3 tags are collided with it, I have this code which works for 1 tag but how do I do 2 or more tags in same line of code I think its by using the && bit of code
please guide me right
thanks
2d game
if (other.gameObject.tag == "Player")
{
anim.Play("fishded");
anim.SetTrigger("Die");
Destroy (gameObject, 1.3f);
GetComponent<AudioSource> ().Play ();
}
}
}
if (other.tag == “Player” && other.tag == “Enemy”)
This condition can never be true, “tag” can only have one value at a time.
You need to keep a list of objects you’re currently colliding with.
The easiest ways I could think of doing this are listed below.
if (other.tag == "Player" && other.tag == "Enemy")
{
anim.Play("fishded");
anim.SetTrigger("Die");
Destroy (gameObject, 1.3f);
GetComponent<AudioSource> ().Play ();
}
If this doesn’t work there is a little messy alternative. As shown:
if (other.tag == "Player")
{
if(other.tag == "Enemy") {
anim.Play("fishded");
anim.SetTrigger("Die");
Destroy (gameObject, 1.3f);
GetComponent<AudioSource> ().Play ();
}
}
If this works, please accept the answer. If not, reply and I will help you further