IEnumerator Patrol() { //Debug.Log("Patrol " + isNewState); //Debug.Log("Moving Enemy"); while (isNewState == false) { yield return(null); //float dist = Vector3.Distance(target.transform.position, transform.position); //Debug.Log("InPatrol" + Mathf.Round(dist)); if (MoveUtil.Move(target.transform.position, cc, patrolPoint, moveSpeed, rotationSpeed)) { //Debug.Log(Vector3.Distance(target.transform.position, transform.position)); if (MoveUtil.DetectPlayer(player.transform, transform, sightRange)) { SetState(State.AttackRun); } if (Vector3.Distance(target.transform.position, transform.position) < 1f) { SetState(State.Idle); } //if (MoveUtil.DetectPlayer(target.transform, gameObject.transform, sightRange)) //{ // SetState(State.AttackRun); //} } } }
/// <summary> /// 输入偏移量 /// </summary> public void Move(int x, int y) { if (_anim != null) { _anim.SetFloat("h", x); _anim.SetFloat("v", y); } var pos = _transform.localPosition.ToPos(); MoveUtil.Move(pos, x, y, _transform); }
protected override IEnumerator AttackRun() { while (isNewState == false) { yield return(null); if (MoveUtil.Move(player.transform.position, cc, sightRange, moveSpeed, rotationSpeed)) { if (MoveUtil.DetectPlayer(player.transform, transform, attackRange)) { SetState(State.Attack); } } if (Vector3.Distance(player.transform.position, transform.position) > sightRange) { target = null; SetState(State.Idle); } } }