BloodItem.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. //血液里面的物质
  5. public class BloodItem : MonoBehaviour {
  6. //物质类型
  7. [SerializeField]
  8. private BloodManager.BloodItemType mType;
  9. private float moveSpeed = 2;
  10. [HideInInspector]
  11. public int nextPointIndex = 0;
  12. private Rigidbody mRig;
  13. private Collider mCol;
  14. private bool isGood;//是否是被用户拾取过的
  15. private bool isReady;//是否准备好被拾取了
  16. void Start () {
  17. if (this.mRig == null)
  18. {
  19. mRig = this.GetComponent<Rigidbody>();
  20. mCol = this.GetComponentInChildren<Collider>();
  21. //this.mRig.maxDepenetrationVelocity = 0.1f;
  22. }
  23. this.GetComponent<RevertComponent>().SetCallBack(ResetBack);
  24. }
  25. void Update () {
  26. }
  27. private void FixedUpdate()
  28. {
  29. Move();
  30. }
  31. private float showTime;
  32. private void OnEnable()
  33. {
  34. isGood = false;
  35. isReady = false;
  36. }
  37. public BloodManager.BloodItemType MType
  38. {
  39. get { return mType; }
  40. }
  41. private Vector3 dir;
  42. public void SetMoveDir(Vector3 dir)
  43. {
  44. if(this.mRig == null)
  45. {
  46. mRig = this.GetComponent<Rigidbody>();
  47. mCol = this.GetComponentInChildren<Collider>();
  48. }
  49. this.mRig.isKinematic = false;
  50. this.mCol.isTrigger = false;
  51. this.mRig.velocity = Vector3.zero;
  52. //Debug.Log("move" + this.mRig.velocity.ToString());
  53. showTime = Time.realtimeSinceStartup;
  54. this.dir = dir;
  55. }
  56. public bool StopMove()
  57. {
  58. //if(this.mRig.isKinematic || !isReady || isGood)
  59. if (this.mRig.isKinematic || isGood)
  60. {
  61. return false;//已经正在被锁定了 不能再次停止 没有被拾取
  62. }
  63. this.mRig.isKinematic = true;
  64. this.mCol.isTrigger = true;
  65. return true;//可以被拾取的 并且 没有被拾取的
  66. }
  67. private void Move()
  68. {
  69. this.mRig.AddForce(dir * 0.1f, ForceMode.Force);
  70. }
  71. private void Huishou()
  72. {
  73. if (isGood)
  74. {
  75. CDebug.Log("add isGood");
  76. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SCORE_ADD, this);
  77. }
  78. else
  79. {
  80. //Debug.Log("add isGood false");
  81. //MessageCenter.Instance.Broadcast(GameEnum.MESSAGE_SCORE_DEC, this);
  82. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SCORE_DEC, this);
  83. }
  84. PrefabManager.Instance.RevertPrefab(this.gameObject, this.gameObject.name);
  85. }
  86. private void OnTriggerEnter(Collider other)
  87. {
  88. if(other.gameObject.layer == 10)
  89. {
  90. CDebug.Log("已经出来了");
  91. isGood = true;
  92. iTween.Stop(this.gameObject);
  93. SetMoveDir(-Vector3.forward);
  94. }
  95. else if (other.name == "RevertBox")
  96. {
  97. Huishou();
  98. }
  99. }
  100. private void ResetBack(RevertComponent comp)
  101. {
  102. //这里是时间耗尽的回掉
  103. }
  104. }