void SwitchState() { if(myState != nextState) { lastState = myState; ExitState(); switch(nextState) { case behav.idle: OnEnterIdle(); break; case behav.attack: OnEnterAttack(); break; case behav.roam: OnEnterRoam(); break; case behav.think: OnEnterThink(); break; case behav.flee: OnEnterFlee(); break; } } }
void ShootTowardPlayer(Vector3 force) { if(canShoot && force != Vector3.zero){ GameObject initBall = Instantiate(Resources.Load("Prefab/Enemy_Ball"), this.transform.position + Vector3.up, Quaternion.identity) as GameObject; initBall.GetComponent<Rigidbody>().AddForce(force, ForceMode.VelocityChange); canShoot = false; this.GetComponent<AudioSource>().Play(); lastShootTime = Time.timeSinceLevelLoad; nextState = behav.roam; Invoke( "SwitchState", 1.5f); } }
//------------------------// void Start() { //register objects player = GameObject.Find("Player"); GameObject ground = GameObject.Find("Ground"); GameManager.instance.Register(this.gameObject); //reset position transform.position = new Vector3(transform.position.x, 0.5f, transform.position.z); //start roaming destination = this.transform.position; nextState = behav.roam; SwitchState(); //define type myType = GameManager.EnemyType.GroundRange; }
void OnHittingWall() { destination = this.transform.position; GetDestination(); CancelInvoke(); if(myState != behav.roam){ nextState = behav.roam; SwitchState(); } }
void ResumeLastState() { nextState = lastState; SwitchState(); }
void OnEnterThink() { myState = behav.think; }
void OnEnterRoam() { myState = behav.roam; if(GameManager.instance.CanAttack()){ nextState = behav.attack; }else{ nextState = behav.roam; } int roamTime = Random.Range(1, 9); Invoke("SwitchState", roamTime); this.GetComponent<Renderer>().material.color = Color.white; GetDestination(); }
void OnEnterIdle() { myState = behav.idle; }
void OnEnterFlee() { myState = behav.flee; }
void OnEnterAttack() { GameManager.instance.AddAttackingEnemy(); myState = behav.attack; this.GetComponent<Renderer>().material.color = Color.red; // Invoke("OnEnterRoam", 4f); }