12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- 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<Animator>();
- AnimatorController animatorController = Resources.Load<AnimatorController>("Dog/AnimatorController/PlaygroundDogBehavior");
- animator.runtimeAnimatorController = animatorController;
- // 加载bbx collider
- BoxCollider boxCollider = dog.AddComponent<BoxCollider>();
- boxCollider.isTrigger = true;
- boxCollider.center = new Vector3(0, 0.225f, 0);
- boxCollider.size = new Vector3(0.2f, 0.45f, 0.6f);
- // 加载script <DogCatchDetection>
- DogCatchDetection dogScript = dog.AddComponent<DogCatchDetection>();
- }
-
- }
|