MB3_DisableHiddenAnimations.cs 748 B

12345678910111213141516171819202122232425
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public class MB3_DisableHiddenAnimations : MonoBehaviour {
  5. public List<Animation> animationsToCull = new List<Animation>();
  6. void Start () {
  7. if (GetComponent<SkinnedMeshRenderer> () == null) {
  8. Debug.LogError ("The MB3_CullHiddenAnimations script was placed on and object " + name + " which has no SkinnedMeshRenderer attached");
  9. }
  10. }
  11. void OnBecameVisible(){
  12. for (int i = 0; i < animationsToCull.Count; i++) {
  13. if (animationsToCull[i] != null) animationsToCull[i].enabled = true;
  14. }
  15. }
  16. void OnBecameInvisible(){
  17. for (int i = 0; i < animationsToCull.Count; i++) {
  18. if (animationsToCull[i] != null) animationsToCull[i].enabled = false;
  19. }
  20. }
  21. }