DogPlaygroundComponentInstall.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using UnityEngine;
  2. using System.Collections;
  3. /* 加载playground场景下狗的特定的component
  4. */
  5. public class DogPlaygroundComponentInstall : MonoBehaviour
  6. {
  7. public string displayDogName; // 在gameobject中显示的名字
  8. public DogProperty dogProperty;
  9. // Start is called once before the first execution of Update after the MonoBehaviour is created
  10. void Start()
  11. {
  12. dogProperty = UserProperty.dogs[GameData.focusDog];
  13. StartCoroutine(DogComponentAdd());
  14. }
  15. // Update is called once per frame
  16. //void Update()
  17. //{
  18. //}
  19. IEnumerator DogComponentAdd()
  20. {
  21. // 等待一帧,确保所有 Start() 方法都执行完成
  22. yield return null;
  23. // 第一帧以后开始执行
  24. GameObject dog = GameObject.Find(displayDogName);
  25. // 加载指定的Animator controller
  26. Animator animator = dog.GetComponent<Animator>();
  27. RuntimeAnimatorController animatorController = Resources.Load<RuntimeAnimatorController>("Dog/AnimatorController/shibaInu/PlaygroundDogBehavior");
  28. //AnimatorController animatorController = new AnimatorController();
  29. if (dogProperty.breed == "shibaInu") { animatorController = Resources.Load<RuntimeAnimatorController>("Dog/AnimatorController/shibaInu/PlaygroundDogBehavior"); }
  30. animator.runtimeAnimatorController = animatorController;
  31. // 加载bbx collider
  32. BoxCollider boxCollider = dog.AddComponent<BoxCollider>();
  33. boxCollider.isTrigger = true;
  34. boxCollider.center = new Vector3(0, 0.225f, 0);
  35. boxCollider.size = new Vector3(0.2f, 0.45f, 0.6f);
  36. // 加载script <DogCatchDetection>
  37. DogCatchDetection dogScript = dog.AddComponent<DogCatchDetection>();
  38. }
  39. }