Cueing an Animation From Another GameObject's Script (Javascript)

Hey everyone,

so I’ve got the basic “collect items for points” script below, and want to add an animation when the player hits the trigger. The animation is attached to the MainCamera object (and must be, as it modifies an ImageEffect), and I want to cue it from this script.


var score = 0;
var scoreText = "Score: 0";
var MyFont : Font;

function OnTriggerEnter( other : Collider ) {
    Debug.Log("OnTriggerEnter() was called");
    if (other.tag == "Coin") {
        Debug.Log("Other object is a coin");
        score += 5;
        scoreText = "Score: " + score;
        Debug.Log("Score is now " + score);

        yield WaitForSeconds (.2);

function OnGUI () { = MyFont;
  GUI.color =;
     GUI.Label (Rect (10, 10, 500, 300), scoreText);


It’s javascript, and I’ve tried a few options, but they seemed to mostly be in C#. Thanks for the help!



Hah! Got it working! Somehow it wasn’t understanding the label I was giving, but since animation.Play() plays the default animation on the camera, I changed it to that and it’s working! I’m sure I can’t have it be the only animation for long, but for now I can work with this. Thanks so much!