Ok, heres the code. The places were the animations are played is on Update() [Line 75] and on KillPlayer() [Line 130]
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class AnimatronicScript : MonoBehaviour {
/*
======================= Variables =======================
*/
public float AIEasyness; //How easy the AI is?
public Transform[] Positions; //Waypoints of this Ai
public AnimationClip[] Poses; //Poses According on what Waypoint he is
public GameObject[] Eyes; //His eyes so i can change it's color
public int CurrentPosition = 0; //Index of the waypoint array
public Texture GameOverTexture; //Gameover Texture
public LaptopScript laptop; //Gameobject with LaptopScript attached
public Image Static; //Image Component
public Sprite[] StaticTextures; //Sprites for the static
public AudioSource[] AudioSources; //AudioSources that will be deactivated
public bool killedPlayer = false; //Player got killed
public Transform JumpscarePos; //Position of the jumpscare
public AnimationClip Jumpscare; //Jumpscare Animation
public AudioSource
ScreamAudio,StaticNoise; //AudioSources
public PowerSanity deactivatePower; //A gameobject with powerSanity Attached
Animator animator;
public bool WTACPlaying = false; //WalkToAirC() is playing?
public bool WTPPlaying = false; //WalkToPlayer() is playing?
public bool guiOn = false; //Gui can be displayed?
public bool stop = false; //Just so stuff is not made more than 1 time
public bool killPlayerPlaying = false; //KillPlayer() is playing?
/*
======================= Random Important Stuff =======================
*/
//Start Soul()
void Awake () {
StartCoroutine(Soul());
animator = GetComponent<Animator>();
}
void LateUpdate(){
//If current position is 5, kill the player
if(CurrentPosition == 5&&!stop){
stop = true;
StartCoroutine(KillPlayer());
}
//If player is still alive
if(!killedPlayer){
//Waypoint setter
transform.position = Positions[CurrentPosition].position;
//Rotation according to the waypoint he is
transform.rotation = Positions[CurrentPosition].rotation;
}
//if the waypoint he is 5
if(CurrentPosition == 5){
//Change the eyes color to black
foreach(GameObject eye in Eyes){
eye.GetComponent<Renderer>().material.color = new Color(0,0,0);
eye.GetComponent<Renderer>().material.SetColor("_ReflectColor",new Color(0,0,0));
}
}
else{
//if not, to white
foreach(GameObject eye in Eyes){
eye.GetComponent<Renderer>().material.color = new Color(1,1,1);
eye.GetComponent<Renderer>().material.SetColor("_ReflectColor",new Color(1,1,1));
}
}
}
//Animation (Pose) Changer
void Update(){
//Change pose according to what waypoint he is
if(killedPlayer==false)
/*if(CurrentPosition==0){
animator.SetBool("Stage",true);
animator.SetBool("Door",false);
animator.SetBool("Party",false);
}
else if(CurrentPosition>0&&CurrentPosition<5){
animator.SetBool("Stage",false);
animator.SetBool("Door",false);
animator.SetBool("Party",true);
}
else if(CurrentPosition==5){
animator.SetBool("Stage",false);
animator.SetBool("Door",true);
animator.SetBool("Party",false);
}
*/
GetComponent<Animation>().Play(Poses[CurrentPosition].name);
print(GetComponent<Animation>().isPlaying+"/"+GetComponent<Animation>().clip);
}
//Play animation of the static
IEnumerator PlayAnimation(){
while(true){
for (int i = 0; i < StaticTextures.Length; i++)
{
Static.sprite = StaticTextures*;*
-
yield return new WaitForSeconds(0.01f);*
-
}*
-
}*
-
}*
-
//Check if theres any waypoint with AirC toggled*
-
int CheckForAirC(){*
-
for(int i = 0;i<Positions.Length;i++){*
_ if(Positions*.gameObject.GetComponent().AirC)_
_ return i; *_
* }*
* return -1;*
* }*
* //When finishes killing the player, play this*
* IEnumerator PlayStatic(){*
* yield return new WaitForSeconds(1.3f);*
* StaticNoise.PlayOneShot(StaticNoise.clip);*
* yield return new WaitForSeconds(2f);*
* StaticNoise.volume = 1;*
* yield return new WaitForSeconds(4.5f);*
* StaticNoise.Stop();*
* }*
* //kill the player*
* IEnumerator KillPlayer(){*
* killPlayerPlaying = true;*
* foreach(GameObject eye in Eyes){*
* eye.GetComponent().material.color = new Color(0,0,0);*
* eye.GetComponent().material.SetColor("ReflectColor",new Color(0,0,0));
_ }*
* StartCoroutine(PlayStatic());*
* yield return new WaitForSeconds(2);*
* laptop.PlayerIsntDead = false;*
* laptop.cameraOpen = false;*
* laptop.gameObject.transform.rotation = new Quaternion(0,0,0,0);*
* laptop.TurnDownLaptop();*
* deactivatePower.enabled = false;*
* killedPlayer = true;*
* foreach(AudioSource audioS in AudioSources){*
* audioS.enabled = false;*
* }*
* transform.position = JumpscarePos.position;*
* transform.rotation = JumpscarePos.rotation;*
* ScreamAudio.PlayOneShot(ScreamAudio.clip);*
_ /animator.SetBool(“Stage”,false);_
_ animator.SetBool(“Door”,false);_
_ animator.SetBool(“Party”,false);_
_ animator.SetBool(“Jumpscare”,true);_
_ /_
_ GetComponent().Play(Jumpscare.name);_
* yield return new WaitForSeconds(Jumpscare.length);*
* Static.gameObject.SetActive(true);*
* StartCoroutine(PlayAnimation());*
* yield return new WaitForSeconds(5f);*
* StopCoroutine(PlayAnimation());*
* guiOn = true;*
* }*
* //Gui for the fail*
* void OnGUI(){*
* if(guiOn){*
* GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),GameOverTexture);*
* if(GUI.Button(new Rect (Screen.width/2 -45,Screen.height - 200,90,30),“Try again?”))*
* Application.LoadLevel(Application.loadedLevelName);*
* }*
* }*
_ /_
_ ======================= AI =======================*_
_ */_
* //Creepy, eh?*
* IEnumerator Soul(){*
* while (true)*
* {*
* yield return new WaitForSeconds(2f);*
* int TheresAirC = CheckForAirC();*
* if(TheresAirC!=-1&&!WTACPlaying){*
* WTACPlaying = true;*
* StopCoroutine(WalkToPlayer());*
* StartCoroutine(WalkToAirC(TheresAirC)); *
* }*
* else if (!killedPlayer&&!WTPPlaying&&!WTACPlaying&&!killPlayerPlaying){*
* WTPPlaying = true;*
* StartCoroutine(WalkToPlayer());*
* }*
* }*
* }*
* //If there’s a Camera with AirC Toggled On, then play this corroutine*
* IEnumerator WalkToAirC(int TheresAirC){*
* yield return new WaitForSeconds(6f);*
* StopCoroutine(KillPlayer());*
* if(TheresAirC<CurrentPosition){*
* CurrentPosition–;*
* GetComponent().Play();*
* }*
* else if(TheresAirC>CurrentPosition){*
* CurrentPosition++;*
* GetComponent().Play();*
* }*
* if(TheresAirC == CurrentPosition){*
* Positions[CurrentPosition].gameObject.GetComponent().AirCToggle();*
* }*
* WTACPlaying = false; *
* }*
* //If there’s not, then go straight kill the player*
* IEnumerator WalkToPlayer(){*
* yield return new WaitForSeconds(AIEasyness);*
* if(!killPlayerPlaying&&!killedPlayer&&!WTACPlaying){*
* int Direction = Random.Range(0,10);*
* //print(Direction);*
* //Walk to the next waypoint*
* if(Direction >=1&&CurrentPosition+1 <= Positions.Length-1){*
* CurrentPosition ++;*
* GetComponent().Play();*
* }*
* //Walk to the previouse waypoint*
* else if(Direction==0&&CurrentPosition-1 >= 0||CurrentPosition+1 >Positions.Length-1){*
* CurrentPosition --;*
* GetComponent().Play();*
* }*
* }*
* WTPPlaying = false;*
* }*
}
So, the problem im having here is that, i was using Unity 4.6, and when Unity 5 came out, i upgraded my project to Unity 5, and when i did that, the animations of the gameobject handling this script stopped from working. It came with a other problem that the gameobject didn’t moved becouse of the broken animation. Now that was fixed. Though the problem that the animations wasn’t being played persisted.
So the problem is that my legacy animations aren’t being played when i upgraded to Unity 5. Any help?