OK this is weird, I have two animations that I start from a C# script, the animations are fine and they work OK but one of them will not play in my UI interface set up? I get the following error:
Invalid Layer Index
UnityEngine.Animator:Play(String)
ScannerAdjustmanager:StartScannerLights() (at Assets/ScannerAdjustmanager.cs:42)
UnityEngine.EventSystems.EventSystem:Update()
In my inspector I have the Animator Unchecked and my C# script is supposed to activate them when I press a UI button, but only one of them works, and I get that error message above? I’ll post my script just incase anyone can see something I’m missing.
using UnityEngine;
using System.Collections;
public class ScannerAdjustmanager : MonoBehaviour {
//Reference to Animations
public GameObject ScannerLightAni;
public GameObject BlueLEDsAni;
//Audio Clip References
public AudioClip Scanner;
//animator reference
private Animator anim;
void Start () {
//unpause the game on start
//Time.timeScale = 1;
//get the animator component
anim = ScannerLightAni.GetComponent<Animator>();
anim = BlueLEDsAni.GetComponent<Animator>();
//disable it on start to stop it from playing the default animation
//anim.enabled = false;
}
public void GoAbort(){
StartCoroutine(LoadAfterDelay("ThreeD_Overview"));
}
IEnumerator LoadAfterDelay(string levelName){
yield return new WaitForSeconds(0.5f); // wait 1 seconds
Application.LoadLevel(levelName);
}
//Start Scanner Animations
public void StartScannerLights(){
//StartCoroutine(AutoDoorOutR());
anim.enabled = true;
anim.Play("ScannerAdjustAnimation");
}
//Start LEDs Animations
public void StartLEDLights(){
//StartCoroutine(AutoDoorOutR());
anim.enabled = true;
anim.Play("ScannerBlueLEDsAni");
//Audio Play
audio.clip = Scanner;
audio.loop = true;
audio.Play();
}
}