Reputation: 5
private void OnCollisionEnter(Collision collision) {}
private void Update()
{
OnCollisionEnter("Here"); <----
}
Upvotes: 0
Views: 76
Reputation: 924
OnCollisionEnter
is an event callback and is not supposed to be called as you have done.
Unity automatically calls it when the object (which is a RigidBody
) collides with another object with a collider
. For example, consider a Player
object colliding with the Enemy
object
public class Player : MonoBehaviour
{
public GameObject player;
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.name == "Enemy")
{
//Destroy Player
}
}
}
Upvotes: 2