public void Injure() { _hp--; _animator.SetTrigger("Injure"); if (_hp <= 0) { //todo:进入结算 Staus = Staus.Lose; } }
public void ChangeStaus(Staus staus) { if (staus == Staus.Patrol) { PatrolStart(); } else if (staus == Staus.Attack) { AttackStart(); } }
public void Init() { _curtime = 0; _resttime = 0.5f; _target = new Vector2(0, 1); _hp = 1; _animator = gameObject.GetComponent <Animator>(); _rigid = gameObject.GetComponent <Rigidbody2D>(); _collider = gameObject.GetComponent <BoxCollider2D>(); Obs = GameObject.FindGameObjectWithTag("GameController").GetComponent <ObsManager>(); Staus = Staus.Gaming; }
//键盘控制移动 public void Move(int h, int v) { _rigid.MovePosition(Vector2.Lerp(transform.position, _target, Time.deltaTime * Speed)); if (_curtime < _resttime) { _curtime += Time.deltaTime; return; } Vector2 tmp = new Vector2(h, v); if (h != 0 || v != 0) { if (_target.x + tmp.x < 0) { return; } _collider.enabled = false; RaycastHit2D hit = Physics2D.Linecast(_target, _target + tmp); _collider.enabled = true; if (hit.transform == null) { _target += tmp; } else { switch (hit.collider.tag) { case "Wall": break; case "Obs": _animator.SetTrigger("Atack"); Obs.Hit(_target + tmp); _target += tmp; break; case "Exit": //todo:进入结算,胜利 Staus = Staus.Win; break; } } _curtime = 0; } }