Stop() public method

public Stop ( ) : void
return void
示例#1
0
    void Update()
    {
        // check health <= 0  change state to tank destroy

        // set overall states here
        if (GetComponent <TeamPlayer>().health <= 20)
        {
            if (GetComponent <TeamPlayer>().health <= 0)
            {
                tankState = "Destroy";
                //GameObject explosion =
                //Instantiate(Resources.Load("Explosion"), transform.position, transform.rotation) as GameObject; // TIDYME: 2018-07-07: no Explosion
            }
            else
            {
                tankState = "Fleeto_Home_Base";
                aiFollow.Resume();
            }
        }


        switch (tankState)
        {
        case "Spawn_Bot":
            // play spawn animation
            // update all player details
            GetComponent <TeamPlayer>().health = 100;
            tankState = "Goto_Enemy_Base";
            break;

        case "Goto_Enemy_Base":
            // set the current target to to an enemy target within range
            currentTarget = FindClosestTarget();


            if (currentTarget == null)
            {
                // if no available targets within range move towards enemy base
                currentTarget = GameObject.Find("EnemyBase");     // TIDYME: 2018-07-07: Use of Find
            }
            else
            {
                // if target found change state to engage target
                tankState = "Engage_targets";
            }

            // set that path finding target to whichever target that has been set
            aiFollow.target = currentTarget.transform;
            break;

        case "Engage_targets":
            // change target if another target is closer to you - as closer targets are more dangeerous
            currentTarget = FindClosestTarget();
            if (currentTarget != null)
            {
                aiFollow.target = currentTarget.transform;
            }

            if (currentTarget != null)
            {
                float distFromTarget = Vector3.Distance(turret.transform.position, currentTarget.transform.position);

                if (distFromTarget <= engageRange)
                {
                    aiFollow.Stop();
                    RotateTurret();
                    if (CheckFiringStatus())
                    {
                        BattleEnemy();
                    }
                    else if (TurretAimStatus())
                    {
                        aiFollow.Resume();
                    }
                }
                else if (distFromTarget <= findEnemyRange && distFromTarget > engageRange)
                {
                    // go near enemy and engage him since he is far

                    // dont engage but move to enemy base
                    aiFollow.Resume();
                    // default action
                    // can add animation or sound here
                }
                else
                {
                    // since no enemy within findEnemyRange go towards enemy base
                    aiFollow.Resume();
                    tankState = "GotoEnemyBase";
                }
            }
            else
            {
                aiFollow.Resume();
                tankState = "GotoEnemyBase";
            }

            break;

        case "Fleeto_Home_Base":
            // move to home base
            currentTarget   = GameObject.Find("HomeBase");
            aiFollow.target = currentTarget.transform;
            if (GetComponent <TeamPlayer>().health >= 50)
            {
                tankState = "Goto_Enemy_Base";
                break;
            }
            else
            {
                currentTarget = FindClosestTarget();
                if (CheckPickups())
                {
                    // change state to getPickups
                    tankState = "Get_PickUps";
                }
            }

            if (GetComponent <TeamPlayer>().health >= 50)
            {
                tankState = "Goto_Enemy_Base";
            }

            break;

        case "Get_PickUps":
            if (CheckPickups() != null)
            {
                // get and move to pickup

                // if managed to get pickup play Pickup animation here

                // update pickup points here
                GetComponent <TeamPlayer>().health += 30;
            }
            else
            {
                tankState = "Fleeto_Home_Base";
            }

            if (GetComponent <TeamPlayer>().health >= 50)
            {
                tankState = "Goto_Enemy_Base";
            }

            break;

        case "Recuperate":
            // play recuperate animation

            // increase health with time
            GetComponent <TeamPlayer>().health += Time.deltaTime * recuperateSpeed;

            // stay till health is beyond 50 percent
            if (GetComponent <TeamPlayer>().health >= 50)
            {
                tankState = "Goto_Enemy_Base";
            }

            break;

        case "Destroy":
            // kill bot here
            // Play explosion animation here
            break;
        }
    }