I just use this: GameObject iceCube = GameObject.CreatePrimitive(PrimitiveType.Cube); to create an ice cube and when I use the AddComponent to add a script like this:
void OnCollisionEnter(Collision collision)
{
if (collision.collider.name == “player”)
{
player_health -= 10;
}
}
It doesn’t work at all. Somehow I cannot even detect the collision and I even print something when colliding but still no result. Any suggestion?
Did you add a collider as well?
cube.AddComponent<BoxCollider>();
This is why you should be using a prefab and use GameObject.Instantiate so Unity will handle all the components and children creation for you.
Thank you for your help!