Created
January 29, 2018 14:38
-
-
Save shrinath-kopare/ad6a3f24946eea5875ab372478db3026 to your computer and use it in GitHub Desktop.
Adding and controlling Animator Controller at runtime using script in Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Anim : MonoBehaviour { | |
public GameObject cg; | |
public RuntimeAnimatorController animator; | |
void Start () { | |
cg.gameObject.AddComponent<Animator>(); | |
cg.gameObject.GetComponent<Animator>().runtimeAnimatorController = animator; | |
} | |
void OnGUI() { | |
if (GUI.Button(new Rect(10, 70, 50, 30), "Fade")){ | |
cg.gameObject.GetComponent<Animator>().SetTrigger("fade"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment