I have a scrip attached to GUI canvas in this script I perform various operation related to game status.
Now I want to detect the hit of a bullet MyBullet
to a target MyTarget
I have tried o add in this script the follow code
function OnCollisionEnter(collision: Collision) {
for (var contact: ContactPoint in collision.contacts) {
if(collision.gameObject.name=="MyTarget" || collision.gameObject.tag=="MyTarget" )
{
Debug.Log("Ball hit Box");
points++;
speed=bullet.velocity;
}
}
}
And nothing happens
I have altso tried to create in Start
function
var target=GameObject.FindGameObjectWithTag("MyTarget");
targetCollider=target.GetComponent.<CapsuleCollider>();
adding this check in Update
function
if(boatCollider.isTrigger){
Debug.Log("Ball hit Box");
points++;
speed=bullet.velocity;
}
With no result.
How could I fix this?
Please note that this script is not attached to MyTarget
object is attached to my GUI canvas object