Where can I get the list of Unity software versions along with a list of their supported versions of Android (APIs)? I can’t find any official documents for this.
3 Answers
3void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == “Sphere” && col.gameObject.tag == “Pyramid”)
{
Destroy (GameObject.FindWithTag(“Pentagon”));
}
}
col.gameObject.tag can’t be both “Sphere” and “Pyramid” at the same time so your && condition will never return true. In your other example you’re using ||.
Debug.Log is your friend here.
Try this is your object:
void OnCollisionEnter(Collision col)
{
Debug.Log(col.gameObject.tag);
}
Notice that the Log happens individually for each time your object collides with something, this means you can only collide with one object each time. Doing an and && operation between tags does not make sense in this case because only ONE object is sent to OnCollisionEnter.
How would you check if you collided with both? One approach would be to cache the LAST collision, and check if it is a Pyramid or a Sphere.
string lastTagCollided = "";
void OnCollisionEnter(Collision col)
{
if(col.gameObject.tag == "Pyramid" && lastTagCollided == "Sphere")
{
// Destroy something
}
if(col.gameObject.tag == "Sphere" && lastTagCollided == "Pyramid")
{
// Destroy something
}
lastTagCollided = col.gameObject.tag;
}
This script will not work when the object collides with other objects than Sphere and Pyramid
– anon74093993Make this script and call it PentagonColliderScript
public bool collidesWithPentagon;
public string other;
void OnCollisionEnter(Collision col)
{
if(col.gameObject.tag == "Pentagon")
{
collidesWithPentagon = true;
if(GameObject.find(other).getComponent<PentagonColliderScript>().collidesWithPentagon)
{
Destroy(col.gameObject);
}
}
}
void onCollisionExit(Collision col)
{
if(col.gameObject.tag == "Pentagon")
{
collidesWithPentagon = false;
}
}
on the sphere set the other value in the inspector to Pyramid and on the Pyramid, set it to sphere. I don’t know if this will work, I am typing this on my mobile phone.
Now this maybe on purpose, but in the destroying on you are saying if the tag is 'sphere' AND 'pyramid'. Where in the other script you are saying if it is 'sphere' OR 'pyramid'. So there is no way for that if to pass since one object cannot have both tags.
– AlexJBoydIs it when it has collided with both at the same time or if it has collided with one or the other that you are intending.
– spooneystone