How to fetch the object which the object collides with? Unity -- collision

 How to fetch the object which the object collides with? Unity -- collision

[Ans]
collision.gameObject.name;

public void OnCollisionEnter(Collision collision)
    {
      
            Debug.Log("collision name:" + collision.gameObject.name);
        
    }

Step1:
make a collision event
with the step in the following link
(my article)

Step2:
In Script,
write the line
Debug.Log("collision name:" + collision.gameObject.name); 

Comments

Popular posts from this blog

GameObject.SetActive() v.s. GameObject.active

output message to Unity Console - Debug.Log() v.s. Debug.LogWarning() v.s. Debug.LogError() v.s. print()