Destroy Object by Hit – Unity3D (C#)


Destroy Object by Hit – Unity3D (C#)

Before implement this code, please check if you add “Rigidbody” component to your objects and “Is Trigger” box is selected. Otherwise, it doesn’t work.

1
2
3
4
5
	void OnTriggerEnter(Collider c){
		if (c.collider.tag == "Enemy") {
			Destroy(c.gameObject);
		}
	}

©Coffee Break Codes – Destroy Object by Hit – Unity3D (C#)

Leave a comment

Your email address will not be published. Required fields are marked *