123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- //血液里面的物质
- public class BloodItem : MonoBehaviour {
- //物质类型
- [SerializeField]
- private BloodManager.BloodItemType mType;
- private float moveSpeed = 2;
- [HideInInspector]
- public int nextPointIndex = 0;
- private Rigidbody mRig;
- private Collider mCol;
- private bool isGood;//是否是被用户拾取过的
- private bool isReady;//是否准备好被拾取了
- void Start () {
- if (this.mRig == null)
- {
- mRig = this.GetComponent<Rigidbody>();
- mCol = this.GetComponentInChildren<Collider>();
- //this.mRig.maxDepenetrationVelocity = 0.1f;
- }
- this.GetComponent<RevertComponent>().SetCallBack(ResetBack);
- }
-
- void Update () {
-
- }
- private void FixedUpdate()
- {
- Move();
- }
- private float showTime;
- private void OnEnable()
- {
- isGood = false;
- isReady = false;
- }
- public BloodManager.BloodItemType MType
- {
- get { return mType; }
- }
- private Vector3 dir;
- public void SetMoveDir(Vector3 dir)
- {
- if(this.mRig == null)
- {
- mRig = this.GetComponent<Rigidbody>();
- mCol = this.GetComponentInChildren<Collider>();
- }
- this.mRig.isKinematic = false;
- this.mCol.isTrigger = false;
- this.mRig.velocity = Vector3.zero;
- //Debug.Log("move" + this.mRig.velocity.ToString());
- showTime = Time.realtimeSinceStartup;
- this.dir = dir;
- }
- public bool StopMove()
- {
- //if(this.mRig.isKinematic || !isReady || isGood)
- if (this.mRig.isKinematic || isGood)
- {
- return false;//已经正在被锁定了 不能再次停止 没有被拾取
- }
- this.mRig.isKinematic = true;
- this.mCol.isTrigger = true;
- return true;//可以被拾取的 并且 没有被拾取的
- }
- private void Move()
- {
- this.mRig.AddForce(dir * 0.1f, ForceMode.Force);
- }
- private void Huishou()
- {
- if (isGood)
- {
- CDebug.Log("add isGood");
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SCORE_ADD, this);
- }
- else
- {
- //Debug.Log("add isGood false");
- //MessageCenter.Instance.Broadcast(GameEnum.MESSAGE_SCORE_DEC, this);
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SCORE_DEC, this);
- }
- PrefabManager.Instance.RevertPrefab(this.gameObject, this.gameObject.name);
- }
- private void OnTriggerEnter(Collider other)
- {
- if(other.gameObject.layer == 10)
- {
- CDebug.Log("已经出来了");
- isGood = true;
- iTween.Stop(this.gameObject);
- SetMoveDir(-Vector3.forward);
- }
- else if (other.name == "RevertBox")
- {
- Huishou();
- }
- }
- private void ResetBack(RevertComponent comp)
- {
- //这里是时间耗尽的回掉
-
- }
- }
|