Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

how to know what object player touches unity 2D

/* 
For this to work, both objects (Player and something that it touches) must have
Any Collider2D component enabled
*/
// If none of them have trigger on.
void OnCollisionEnter2D(Collision2D other)
{//this is how to get name of the other object
	string otherObjectName = other.gameObject.name;
 //this is how to get tag of the other object
  	string otherObjectTag = other.gameObject.tag;
}
// If at least one of them has Trigger on, use this function instead.
void OnTriggerEnter2D(Collider2D other){

}
 
PREVIOUS NEXT
Tagged: #object #player #touches #unity
ADD COMMENT
Topic
Name
9+5 =