using UnityEditor.Animations; using UnityEngine; using System.Collections; /* 加载playground场景下狗的特定的component */ public class DogComponentInstall : MonoBehaviour { public string dogName; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { StartCoroutine(DogComponentAdd()); } // Update is called once per frame //void Update() //{ //} IEnumerator DogComponentAdd() { // 等待一帧,确保所有 Start() 方法都执行完成 yield return null; // 第一帧以后开始执行 GameObject dog = GameObject.Find(dogName); // 加载指定的Animator controller Animator animator = dog.GetComponent(); AnimatorController animatorController = Resources.Load("Dog/AnimatorController/PlaygroundDogBehavior"); animator.runtimeAnimatorController = animatorController; // 加载bbx collider BoxCollider boxCollider = dog.AddComponent(); boxCollider.isTrigger = true; boxCollider.center = new Vector3(0, 0.225f, 0); boxCollider.size = new Vector3(0.2f, 0.45f, 0.6f); // 加载script DogCatchDetection dogScript = dog.AddComponent(); } }