Hi there I am trying to script my animation for my game, but its coming up with errors that I dont understand, as I am still new to this and learning. Please can someone help me please?
public class FlameAnimations : MonoBehaviour {
public int LightMode;
public GameObject FlameLight;
void Update () {
if (LightMode == 0) {
StartCoroutine (AnimateLight ());
}
}
IEnumerator AnimateLight () {
LightMode = Random.Range (1, 4);
if (LightMode == 1) {
FlameLight.GetComponent ().Play (“TorchAnim1”);
}
if (LightMode == 2) {
FlameLight.GetComponent ().Play (“TorchAnim2”);
}
if (LightMode == 3) {
FlameLight.GetComponent ().Play (“TorchAnim3”);
}
yield return new WaitForSeconds (0.99f);
LightMode = 0;
}
}
The problem with your code is that you are missing the using directives. Without them the compiller does not know from where to take the types and methods that you use in your code.
Without using directives, you are not importing the libraries.
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
public class FlameAnimations : MonoBehaviour {
public int LightMode;
public GameObject FlameLight;
void Update () {
if (LightMode == 0) {
StartCoroutine (AnimateLight ());
}
}
IEnumerator AnimateLight () {
LightMode = Random.Range (1, 4);
if (LightMode == 1) {
FlameLight.GetComponent<Animation> ().Play ("TorchAnim1");
}
if (LightMode == 2) {
FlameLight.GetComponent<Animation> ().Play ("TorchAnim2");
}
if (LightMode == 3) {
FlameLight.GetComponent<Animation> ().Play ("TorchAnim3");
}
yield return new WaitForSeconds (0.99f);
LightMode = 0;
}
}