How to have a trigger activate animation on another game object.

In order to be able to accurate explain my problem, I will use an analogy.

If you have played Portal 2, you know that if you place a cube on a button, something will activate, say open a door. I want to have a similar mechanic. I know the button will be a trigger object and it will check, but how to connect the button being triggered to the door opening via C# scripts is what I don’t know how to do.

I guess in short, activating another object through the script of another unrelated object (assume the two aren’t colliding or near each other) is what I’m having trouble with.

Thanks! Let me know if you need ore information.


using UnityEngine;
using System.Collections;
public class TriggerScript: MonoBehaviour {
public Animation anim;
void OnTriggerEnter() {
ani.enabled = true;
Add this script to Trigger Object.Add Animation component of Door to anim in Inspector
Disable Animation component on Door GameObject.
or watch this - YouTube

The easiest way would be to have one script on the trigger and one script on the door. the script on the trigger should have a public variable of type door script. In the inspector you should then be able to drag the door onto the variable of the trigger now visible in the inspector. The whole gameobject suffices, the script will be picked automatically instead. now you should be able to call upon public methods in the trigger script on the door script variable.