Esempio n. 1
0
    }     // chase

    void Attack()
    {
        navmesh_Agent.velocity  = Vector3.zero;
        navmesh_Agent.isStopped = true;

        attack_Timer += Time.deltaTime;

        if (attack_Timer > wait_Before_Attack)
        {
            //转向玩家
            Vector3 relativePos = target.position - transform.position;
            float   angle       = Vector3.Angle(relativePos, transform.forward);
            if (angle > viewAngle / 2)
            {
                Quaternion rotation = Quaternion.LookRotation(relativePos, Vector3.up);
                transform.rotation = rotation;
            }

            enermy_Animator.Attack();

            attack_Timer = 0f;

            // play attack sound
            enermyAudio.Play_AttackSound();
        }

        if (Vector3.Distance(transform.position, target.position) >
            attack_Distance + chase_After_Attack_Distance)
        {
            Enermy_State = EnermyState.CHASE;
        }
    } // attack
Esempio n. 2
0
	public void Die()
	{
		int score = PlayerPrefs.GetInt("Score");
		score += 10;
		PlayerPrefs.SetInt("Score", score);
//		GameObject.Destroy(gameObject);
		State = EnermyState.Ready;
		gameObject.SetActive(false);
	}
Esempio n. 3
0
 void Start()
 {
     Enermy_State = EnermyState.PATROL;
     patrol_Timer = patrol_For_This_Time;
     //attack the enermy first gets to the player
     attack_Timer           = wait_Before_Attack;
     current_Chase_Distance = chase_Distance;
     healthScript           = this.GetComponent <HealthScript>();
 }
Esempio n. 4
0
    public void Die()
    {
        int score = PlayerPrefs.GetInt("Score");

        score += 10;
        PlayerPrefs.SetInt("Score", score);
//		GameObject.Destroy(gameObject);
        State = EnermyState.Ready;
        gameObject.SetActive(false);
    }
Esempio n. 5
0
 void Start()
 {
     Init(
         5, 1, 1, 1, 1, 1
         );
     animator    = this.transform.Find("model").GetComponent <Animator>();
     enermystate = new PathFinding(this);
     GetWaypoint();
     CurrentHp = this.hp;
     _timer    = new GameTimer(0.2f);
 }
Esempio n. 6
0
 public void OnDead()
 {
     IsDead = true;
     //稍微延迟一会再读取动画时间
     // animator.Play("Die");
     // //动画执行完成后
     // Timer.Register(0.8f, (delegate
     // {
     enermystate = new PathFinding(this);
     this.gameObject.SetActive(false);
     // }));
 }
Esempio n. 7
0
    } // patrol

    void Chase()
    {
        // enable the agent to move again
        navmesh_Agent.isStopped = false;
        navmesh_Agent.speed     = chase_Speed;

        // set the player's position as the destination
        // because we are chasing(running towards) the player
        navmesh_Agent.SetDestination(target.position);

        if (navmesh_Agent.velocity.sqrMagnitude > 0)
        {
            enermy_Animator.Run(true);
        }
        else
        {
            enermy_Animator.Run(false);
        }

        // if the distance between enemy and player is less than attack distance
        if (Vector3.Distance(transform.position, target.position) <= attack_Distance)
        {
            // stop the animations
            enermy_Animator.Run(false);
            enermy_Animator.Walk(false);
            Enermy_State = EnermyState.ATTACK;
            attack_Timer = wait_Before_Attack;
            // reset the chase distance to previous
            if (chase_Distance != current_Chase_Distance)
            {
                chase_Distance = current_Chase_Distance;
            }
        }
        else if (Vector3.Distance(transform.position, target.position) > chase_Distance)
        {
            // player run away from enemy

            // stop running
            enermy_Animator.Run(false);

            Enermy_State = EnermyState.PATROL;

            // reset the patrol timer so that the function
            // can calculate the new patrol destination right away
            patrol_Timer = patrol_For_This_Time;

            // reset the chase distance to previous
            if (chase_Distance != current_Chase_Distance)
            {
                chase_Distance = current_Chase_Distance;
            }
        } // else
    }     // chase
Esempio n. 8
0
	public void Show()
	{
		int i = UnityEngine.Random.Range(0, 3);
		CarDirection dir = CarDirection.Center;
		if (i == 0) {
			dir = CarDirection.Center;
		} else if (i == 1) {
			dir = CarDirection.Left;
		} else if (i == 2) {
			dir = CarDirection.Right;
		}

		Move(dir);

		State = EnermyState.Show;
		gameObject.SetActive(true);
	}
Esempio n. 9
0
    IEnumerator TimeCount()
    {
        if (localEnermyState != EnermyState.Dead)
        {
            MovementTimer += Time.deltaTime;
        }

        //Walk
        if (MovementTimer <= TimeForWalk)
        {
            localEnermyState = EnermyState.Walk;
        }

        //Idle
        else if (MovementTimer > TimeForWalk && MovementTimer <= TimeFromWalkToIdle && distance > AttackRange)
        {
            localEnermyState = EnermyState.Idle;
        }

        //Reset
        else if (MovementTimer > TimeFromWalkToIdle)
        {
            MovementTimer = 0;
        }

        //Attack
        if (distance <= AttackRange)
        {
            localEnermyState = EnermyState.Attack;
        }

        //Die
        if (enemyCtrl.HP <= 0)
        {
            localEnermyState = EnermyState.Die;
            DieTimer        += Time.deltaTime;
        }
        if (localEnermyState == EnermyState.Die && DieTimer >= dead)
        {
            localEnermyState = EnermyState.Dead;

            yield return(0);
        }
    }
Esempio n. 10
0
    public void Show()
    {
        int          i   = UnityEngine.Random.Range(0, 3);
        CarDirection dir = CarDirection.Center;

        if (i == 0)
        {
            dir = CarDirection.Center;
        }
        else if (i == 1)
        {
            dir = CarDirection.Left;
        }
        else if (i == 2)
        {
            dir = CarDirection.Right;
        }

        Move(dir);

        State = EnermyState.Show;
        gameObject.SetActive(true);
    }
Esempio n. 11
0
    void Patrol()
    {
        // tell nav agent that he can move
        navmesh_Agent.isStopped = false;
        navmesh_Agent.speed     = walk_Speed;

        // add to the patrol timer
        patrol_Timer += Time.deltaTime;

        if (patrol_Timer > patrol_For_This_Time)
        {
            SetNewRandomDestination();

            patrol_Timer = 0f;
        }

        if (navmesh_Agent.velocity.sqrMagnitude > 0)
        {
            enermy_Animator.Walk(true);
        }
        else
        {
            enermy_Animator.Walk(false);
        }

        // test the distance between the player and the enemy
        if (Vector3.Distance(transform.position, target.position) <= chase_Distance)
        {
            enermy_Animator.Walk(false);

            Enermy_State = EnermyState.CHASE;

            // play spotted audio
            enermyAudio.Play_ScreamSound();
        }
    } // patrol
Esempio n. 12
0
    // Use this for initialization
    void Start()
    {
        localEnermyState = EnermyState.Idle;

        Target = GameObject.Find("Player").transform;

        distance = Vector3.Distance(Target.position, transform.position);


        //		Debug.Log ("Dis : " + distance);

        enermySceneManager = GameObject.Find("EnermySceneManager").transform.GetComponent <EnermySceneManager>();

        if (enermySceneManager.turns == 0)
        {
            CurrentEnemyDieAudio = SlimeDieAudio;
        }
        if (enermySceneManager.turns == 1)
        {
            CurrentEnemyDieAudio = TurtleDieAudio;
        }

        StartCoroutine(EnermyMovment());
    }
Esempio n. 13
0
 public void SetState(EnermyState state)
 {
     enermystate = state;
 }