Example #1
0
    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;
            }
        }
    }
Example #2
0
    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);
        }
    }
Example #3
0
    //------------------------//
    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;
    }
Example #4
0
 void OnHittingWall()
 {
     destination = this.transform.position;
     GetDestination();
     CancelInvoke();
     if(myState != behav.roam){
         nextState = behav.roam;
         SwitchState();
     }
 }
Example #5
0
 void ResumeLastState()
 {
     nextState = lastState;
     SwitchState();
 }
Example #6
0
 void OnEnterThink()
 {
     myState = behav.think;
 }
Example #7
0
    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();
    }
Example #8
0
 void OnEnterIdle()
 {
     myState = behav.idle;
 }
Example #9
0
 void OnEnterFlee()
 {
     myState = behav.flee;
 }
Example #10
0
 void OnEnterAttack()
 {
     GameManager.instance.AddAttackingEnemy();
     myState = behav.attack;
     this.GetComponent<Renderer>().material.color = Color.red;
     //		Invoke("OnEnterRoam", 4f);
 }