Hi.
I’m new to unity, but made a object(Man) walking around.
Then I spread some balls(Bluberry) using this code.
for (int y=0; y<numBlueberry; ++y)
{
GameObject inst = Instantiate(Blueberry, new Vector3(Random.Range(-20.0f, 20.0f), 1, Random.Range(-20.0f, 20.0f)), Quaternion.identity);
inst.name = "Blueberry1";
}
Then I try to detect collision.
private void OnCollisionEnter(Collision collision)
{
LogCollsiionEnter.text = "On Collision Enter:" + collision.gameObject.name;
//Destroy(collision.gameObject);
}
}
The Bluberry1 name is not appearing.
If the man walk into an other object witch is not a prefab , the name will show.
If I do the destroy it will work. But I’m not able to sort out by name or tag.
Also if I don’t tick ‘is trigger’ the man stops when walking into a blueberry.
I have also tried collision.collider.name but same result.
What is it I’m getting when it comes to Prefabs and collision ?
I need to be able to sort on collision.
Thankful for all help.
Greeting Kaizen.