So I want to play the animation “Take 001” which is on the object “LargeDoorGeometry_1” and is enabled. The first script takes my actions which tells the game it is a door, i’m looking at it, it is less than a meter away and I pressed use. I know this works because I had it print “Winner” when I did this. Now I need to get the animation to play and that’s where the issue is. I set up a variable that is supposed to be accessible from the script attached to the door. However I’m not getting feedback from the variable and the animation line is giving me an error saying “Expressions in statements must only be executed for their side-effects.” The Code is Below.
#pragma strict
var doorHit : boolean;
var doorBoolean : boolean;
var Hitinfo : RaycastHit;
var door : GameObject;
var doorParent : GameObject;
static var playDoorAnimation : boolean;
//Set Variable Initial States
playDoorAnimation = false;
doorBoolean = false;
door = GameObject.Find("/LargeDoorGeometry_1/polySurface1");
doorParent = GameObject.Find("/LargeDoorGeometry_1");
playDoorAnimation = false;
function Update () {
var ray : Ray = camera.ScreenPointToRay (Vector3(Screen.width / 2,Screen.height / 2,0));
//Launch Raycast
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 100)) {
Debug.DrawLine (ray.origin, hit.point);
//Is it a door?
if (hit.transform.gameObject == door) {
doorBoolean = true;
}
//If it's a door & it is within one meter of the camera & the player presses E, open the door
if (doorBoolean == true && hit.distance < 1 && Input.GetButtonDown("Use")) {
playDoorAnimation = true;
}
}
}
Here Is The Second Script, this one is attached to the door, so the animation should play.
#pragma strict
function Update () {
if (RaycastFromPixels.playDoorAnimation == false) {
print("NotWorking");
}
if (RaycastFromPixels.playDoorAnimation == true) {
animation.Play;
}
}