I am trying to play another animation by accessing another animatorcontroller.How would i correct this script? Code (CSharp): using UnityEngine; using System.Collections; public class ActivateAnimation : MonoBehaviour { void OnCollisionEnter (Collision col) { if(col.gameObject.name == "prop_powerCube") { anim = GetComponent<Animator>(); anim.runtimeAnimatorController = AnimationforPioyu ; } } }
I don't know much about animation, but from your script i can see that the variable anim is not declared but is used. What is AnimationforPioyu ? Also is good practice to not use GetComponent after initialization. Code (CSharp): using UnityEngine; using System.Collections; public class ActivateAnimation : MonoBehaviour { Animator anim; void Start() { anim=GetComponent<Animator>(); } void OnCollisionEnter (Collision col) { if(col.gameObject.name == "prop_powerCube") { anim.runtimeAnimatorController = AnimationforPioyu ; } } }