Collide with trigger

Hi guys, i have a problem.
I have a player (without the controller script) and a trigger.
I’m trying to do that if the player collide with the trigger, something happen.
The problem is I can’t use the OnTriggerStay property of the gameobject with the trigger for gameplay reasons, because the script that check that the player is into the trigger MUST be assigned to the player game object. Can someone help me?

You could use OnTriggerEnter
and SendMessage to let the player object know that it collided with the object.

Yes, but unfortunatly for scripting reasons I can’t assign nothing to the gameobject with the trigger! Other solutions?

You don’t have to assign anything to the gameobject with the trigger.

// Attach this to the trigger gameobject
	void OnTriggerEnter(Collider hit)
	{
		if(hit.gameObject.tag == "Player")
		{
			hit.transform.SendMessage("PlayerTriggered",SendMessageOptions.DontRequireReceiver);
		}
	}
// Attach this to the player gameobject
	void PlayerTriggered()
	{
		// This gets called when the player enters your gameobjects trigger.
		// Do whatever you want here.
	}

If it’s because you instantiate the gameobject with trigger you could use something like this:

GameObject clone =  Instantiate(prefab) as GameObject;
clone.AddComponent("YourScript"); // Adds the script "YourScript"

Yes, it’s a good idea! Thank you very much :smile: