using UnityEditor.Animations; using UnityEngine; using System.Collections; /* 加载playground场景下狗的特定的component */ public class DogPlaygroundComponentInstall : MonoBehaviour { public string displayDogName; // 在gameobject中显示的名字 public DogProperty dogProperty; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { dogProperty = UserProperty.dogs[GameData.focusDog]; StartCoroutine(DogComponentAdd()); } // Update is called once per frame //void Update() //{ //} IEnumerator DogComponentAdd() { // 等待一帧,确保所有 Start() 方法都执行完成 yield return null; // 第一帧以后开始执行 GameObject dog = GameObject.Find(displayDogName); // 加载指定的Animator controller Animator animator = dog.GetComponent(); AnimatorController animatorController = new AnimatorController(); if (dogProperty.breed == "shibaInu") { animatorController = Resources.Load("Dog/AnimatorController/shibaInu/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(); } }