// Use this for initialization void Start() { //初始化赋值 GameManagerObject = GameObject.FindGameObjectsWithTag("GameManager")[0]; GameManager = GameManagerObject.GetComponent <GameManager>(); PlayerObject = GameManager.Player; TargetPlayer = PlayerObject.GetComponent <Player>(); DoorObject = GameManager.Door; Door = DoorObject.GetComponent <Door>(); /*自身属性赋值*/ MonsterAnimator = GetComponent <Animator>(); MonsterTransform = GetComponent <Transform>(); }
/*移动到城门前,攻击城门*/ protected void AttackDoor() { turnLeft(); Vector3 DoorPosition; DoorPosition = DoorObject.GetComponent <Transform>().position; float xDistance = this.GetComponent <Transform>().position.x - DoorPosition.x; if (xDistance > DoorAttackDistance) { // 尚未到达大门 MonsterAnimator.SetBool("isRun", true); Vector3 translator = new Vector3(speed, 0.0f, 0.0f); MonsterTransform.Translate(translator); } else { //已经到达大门处 MonsterAnimator.SetBool("isRun", false); MonsterAnimator.SetTrigger("SwordAttack"); //播放攻击动画 } }