Problem with Collision

Hello all! I have a problem with collision. I want my FPS controller to do something when it is inside a triggered collider of an empty gameobject. There are 3 gameobjects of this type in the scene with the same tag. I made this code, but it has no result:

var fishSpot: BoxCollider;

function Start () {
fishSpot = GameObject.FindGameObjectsWithTag("FishingSpot");
}

function OnControllerColliderHit(hit : ControllerColliderHit){
	if (hit.collider == fishSpot)
		print ("say something!!!");
}

Thank you for any help!!! :slight_smile:

You are assigning a GameObject to a BoxCollider variable. Just compare the name:

#pragma strict

function OnControllerColliderHit(hit : ControllerColliderHit){
     if (hit.collider.name == "FishingSpot")
         print ("say something!!!");
 }

There is a more efficient way of doing this … there is a In built function that runs every time the the gameobject to which the script is attached Collides with any object … it is OnCollisionEnter … then assign the triggering game object a tag and then compare the tag string.

#pragma strict

function void OnCollisionEnter(Collider col)
{
if(col.gameobject.tag == "triggerTag")
{//Do something.}
}

i’m sorry if there is any java script specific mistake … coz i’ve never used it … I think you get the idea of how your code should look like … and the col is automatically assigned by the engine during run time during collision … and don’t place this on your character … place it on your trigger and then reference your character if you have to do something …

I figured it out! You must use the OnTriggerStay function and apply it the collider!
If anyone is wondering this the way! :slight_smile: