Skip to content

Instantly share code, notes, and snippets.

@shrinath-kopare
Created January 29, 2018 14:38
Show Gist options
  • Save shrinath-kopare/ad6a3f24946eea5875ab372478db3026 to your computer and use it in GitHub Desktop.
Save shrinath-kopare/ad6a3f24946eea5875ab372478db3026 to your computer and use it in GitHub Desktop.
Adding and controlling Animator Controller at runtime using script in Unity
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