Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

how to detect collision in unity

void OnCollisionEnter(Collision collision)
{
	if(collision.gameObject.tag == "yourNameOfObject")
    {
    	//This is example
        Debug.Log("Hit Object");
        //code your thing here
    }
}
Comment

check for collision unity c#

void OnCollisionEnter(Collision col) { }
Comment

detect collision in unity

/* Both objects have to have a Collider and one object has to have a Rigidbody for these Events to work */
private void OnCollisionEnter(Collision hit) {    
  Debug.Log(gameObject.name + " hits " + hit.gameObject.name); 
}
private void OnCollisionStay(Collision hit) {  
  Debug.Log(gameObject.name + " is hitting " + hit.gameObject.name); 
}
private void OnCollisionExit(Collision hit) { 
  Debug.Log(gameObject.name + " stopped hitting " + hit.gameObject.name); 
}
// For 2D
private void OnCollisionEnter2D(Collision2D hit) { }
private void OnCollisionStay2D(Collision2D hit) { }
private void OnCollisionExit2D(Collision2D hit) { }
Comment

PREVIOUS NEXT
Code Example
Csharp :: convert html to pdf c# 
Csharp :: c# kill one excel process 
Csharp :: c# add element to array 
Csharp :: c# is odd number 
Csharp :: where in used in linq c# 
Csharp :: c# struct 
Csharp :: join array in c# 
Csharp :: verify if number c# 
Csharp :: c# convert long to int 
Csharp :: click in vue 
Csharp :: unity rotate around axis 
Csharp :: c# xml to json 
Csharp :: check if value in list c# 
Csharp :: c# int 
Csharp :: remove force unity 
Csharp :: multidimensional arrays c# 
Csharp :: All Possible SubString 
Csharp :: linq from multiple tables 
Csharp :: c# example code 
Csharp :: replace multiple characters in string c# 
Csharp :: unity activate gameobject via script 
Csharp :: prevent system shutdown c# 
Csharp :: instantiate prefab unity 
Csharp :: unity lerp 
Csharp :: c# null conditional operator if statement 
Csharp :: remove header visual studio android 
Csharp :: enum in c# 
Csharp :: max index array c# 
Csharp :: combine two arraylist c# 
Csharp :: c# clear console read chache 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =