Error in the Unity3D

Hello. I want to start animating board when player moves into invisible GameObject but Unity shows 2 errors. Here is the code:

#pragma strict

function Start () {
var Board = GameObject.Find("Board");
}

function Update () {

}

function OnTriggerEnter(collider:Collider) {
Board.PlayAnimation("Board rotating");
}

function OnTriggerExit(collider:Collider) {
Board.StopAnimation();
}

Help me, please!
Artyom.

First, create your variable by name “Board” as global:

 var Board: GameObject = null;

 function Start () {
  Board = GameObject.Find("Board");
 }

 function Update () {

 }

 function OnTriggerEnter(collider:Collider) {
  Board.animation.Play("Board Rotating");
 }

 function OnTriggerExit(collider:Collider) {
  Board.animation.Stop();
 }

And, etc. Check in Inspector, that object “Board” have component “Animation” and this component have animation clip by name “Board Rotating”. I hope that it will help you.

Your Board varible is only in the scope of the Start method. You need to make it so other methods can see it like so:

#pragma strict
     
    var Board : GameObject;
    
    function Start () {
    Board = GameObject.Find("Board");
    }
     
    function Update () {
     
    }
     
    function OnTriggerEnter(collider:Collider) {
    Board.PlayAnimation("Board rotating");
    }
     
    function OnTriggerExit(collider:Collider) {
    Board.StopAnimation();
    }

Here is a website about scope: Programing Introduction: Scope