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 :: unity play particle system 
Csharp :: how to reload current scene unity 
Csharp :: wpf numeric only textbox 
Csharp :: unity to integer 
Csharp :: kotlin random number 
Csharp :: orderby c# randomize 
Csharp :: c# count files in directory and subdirectories 
Csharp :: unity how to copy something to the clipboard 
Csharp :: unity application quit 
Csharp :: Animator.GotoState: State could not be found UnityEngine.Animator:Play (string) 
Csharp :: c# check if string is empty 
Csharp :: c# get directory of executable 
Csharp :: linq unique count property 
Csharp :: c# copy to clipboard 
Csharp :: unity instantiate empty gameobject 
Csharp :: c# how to delete a file 
Csharp :: remove repeated items in a list unity 
Csharp :: remove all non number in c# 
Csharp :: c# insert into database 
Csharp :: how to make c# program run cmd commands 
Csharp :: c# take first 4 characters of string 
Csharp :: how to write blank lines in c#.net 
Csharp :: unity projectile spread 
Csharp :: how to set image Source in the code C# 
Csharp :: How To Copy a text C# unity 
Csharp :: how to make a dragable object in unity2D 
Csharp :: how to make a game 
Csharp :: how to log out of unity asset store 
Csharp :: reference to another script unity 
Csharp :: c# filter non alphanumeric characters 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =