Eagle32349
Eagle32349

Reputation: 5

In Unity I can't figure out what to put as a parameter

private void OnCollisionEnter(Collision collision) {}
private void Update()
{
    OnCollisionEnter("Here"); <----
}

Upvotes: 0

Views: 76

Answers (1)

WisdomSeeker
WisdomSeeker

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

Related Questions