コード例 #1
0
    // Use this for initialization
    void Start()
    {
        mps = gameObject.GetComponent <ManagePlayerState>();
        if (!mps)
        {
            print("ManageAIPlayer: Couldn't get player state!");
        }
        //opponentsManager = theOpponent.GetComponent<ManagePlayerState>();

        inOffenseMode = mps.offenseMode;

        if (inOffenseMode)
        {
            currentAIState = eAIStates.ShootLaser;
        }
        else
        {
            currentAIState = eAIStates.ShootShield;
        }
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (thrustDrag < 0)
        {
            thrustDrag = 0;
        }
        if (rotateDrag < 0)
        {
            rotateDrag = 0;
        }

        rigidbody.drag        = thrustDrag;
        rigidbody.angularDrag = rotateDrag;


        // ---------- AI State Changers ----------- //

        if (healthArrived)
        {
            healthArrived = false;
            currentTarget = null;

            // DETERMINE IF TO CHASE HEALTH
            int currHealth = mps.GetHealth();

            if (currHealth < 40)
            {
                currentAIState = eAIStates.ChaseHealth;
            }
        }

        if (relicArrived)
        {
            relicArrived  = false;
            currentTarget = null;

            // DETERMINE IF TO CHASE RELIC
            float currHealth = mps.GetHealth();

            if (currHealth > 60)
            {
                currentAIState = eAIStates.ChaseRelic;
            }
        }


        if (offenseOrDefenseJustChanged)
        {
            offenseOrDefenseJustChanged = false;
            currentTarget = null;

            // DETERMINE IF TO FIRE TO DEFEND
            if (inOffenseMode)
            {
                currentAIState = eAIStates.ShootLaser;
            }
            else
            {
                currentAIState = eAIStates.ShootShield;
            }
        }

        if (gotPowerup)
        {
            gotPowerup    = false;
            currentTarget = null;

            // DETERMINE IF TO FIRE TO DEFEND
            if (inOffenseMode)
            {
                currentAIState = eAIStates.ShootLaser;
            }
            else
            {
                currentAIState = eAIStates.ShootShield;
            }
        }

        // ---------- AI State Implementers ------- //

        switch (currentAIState)
        {
        case eAIStates.ChaseHealth:
            ChaseHealth(); break;

        case eAIStates.ChaseRelic:
            ChaseRelic(); break;

        case eAIStates.ShootLaser:
            ShootLaser(); break;

        case eAIStates.ShootShield:
            ShootShield(); break;
        }
    }