コード例 #1
0
 public override void Initialize()
 {
     runTimer      = true;
     agentRb       = GetComponent <Rigidbody>();
     agentAnimator = GetComponent <AgentAnimator>();
     uIController  = FindObjectOfType <UIController>();
 }
コード例 #2
0
    void FixedUpdate()
    {
        if (Alive())
        {
            PlayerNearby = LookForPlayer();
            if (!Patrol && !PlayerNearby && !(activeState is IdleState))
            {
                SetState(new IdleState());
            }
            else if (Patrol && !PlayerNearby && !(activeState is PatrolState))
            {
                SetState(new PatrolState());
            }
            else if (PlayerNearby && !IsPlayerReachable() && !(activeState is HideState))
            {
                SetState(new HideState());
            }
            else if (PlayerMeleeRange() && !(activeState is MeleeAttackState))
            {
                SetState(new MeleeAttackState());
            }
            else if (PlayerNearby && !PlayerMeleeRange() && IsPlayerReachable() && !(activeState is ChaseState))
            {
                SetState(new ChaseState());
            }

            activeState.Act();
        }
        if (!Alive() && !triggeredDeath)
        {
            triggeredDeath = true;
            AgentAnimator.SetTrigger("Death");
        }
    }
コード例 #3
0
 void FixedUpdate()
 {
     onGround = CheckGrounded();
     if (AgentRigidbody.velocity.y < 0)          //if player character is falling and not on a moving platform
     {
         AgentAnimator.SetBool("Falling", true); //play falling animation. This can't be a trigger because we are unsure how far the player character is falling and so the animation has to be played
     }                                           // until explicitly told to stop. (i.e boolean is false again)
     HandleLayers();
     //prioritise getting powerup but ignore if player is closer to it
     //otherwise melee attack player.
     UpdateImmunity();
     myHealthBar.UpdateHealth(hitpoints, 800f);
     UpdatePowerUp();
     if (!MeleePowerUp && (!powerupSpriteRenderer.enabled || playerObstructingPowerup()) && !PlayerMeleeRange())
     {
         if (!(activeState is RangedAttackState))
         {
             SetState(new RangedAttackState());
         }
     }
     else if (powerupSpriteRenderer.enabled && !playerObstructingPowerup() && PowerUpReachable())
     {
         if (!(activeState is SeekPowerState))
         {
             SetState(new SeekPowerState());
         }
     }
     else if (!(activeState is MeleeAttackState))
     {
         SetState(new MeleeAttackState());
     }
     activeState.Act();
 }
コード例 #4
0
ファイル: Boss.cs プロジェクト: gkjolin/2D-Platformer
 private void Jump()
 {
     if ((onGround))  //if the player presses space and we aren't already jumping or falling
     {
         onGround = false;
         AgentRigidbody.AddForce(new Vector2(0, jumpSpeed));    // make the player character jump (i.e apply a positive force on the y axis)
         AgentAnimator.SetTrigger("Jump");                      // Trigger the jump animation
     }
 }
コード例 #5
0
 protected override void TakeDamage(int hp)
 {
     if (!Alive())
     {
         AgentAnimator.SetTrigger("Death");
         return;
     }
     base.TakeDamage(hp);
     Immunity = true;
 }
コード例 #6
0
 private void HandleLayers()  //If the Player character is in the air we need to have the air layer fully weighted so that we play air animations, otherwise set the weight to 0 to play ground animations.
 {
     if (!onGround)
     {
         AgentAnimator.SetLayerWeight(1, 1);  //set weight for air layer (layer 1) to full (1)
     }
     else
     {
         AgentAnimator.SetLayerWeight(1, 0); //set weight for air layer (layer 1) to none (0)
     }
 }
コード例 #7
0
ファイル: Boss.cs プロジェクト: gkjolin/2D-Platformer
    public override void OnTriggerEnter2D(Collider2D EnterredObject)
    {
        if (EnterredObject.tag == "JumpNotify")
        {
            Jump();
        }
        if (EnterredObject.tag == "PhaseTwo")
        {
            SecondPhaseReached = true;
            SecondPhase        = false;
            Debug.Log("Second Phase Reached.");
            AgentAnimator.SetFloat("speed", 0);
        }
        if (EnterredObject.tag == "PhaseThree")
        {
            ThirdPhaseReached = true;
            ThirdPhase        = false;
            AgentAnimator.SetFloat("speed", 0);
        }
        if (EnterredObject.tag == "PhaseFour")
        {
            FourthPhaseReached = true;
            FourthPhase        = false;
            AgentAnimator.SetFloat("speed", 0);
        }

        if (EnterredObject.tag == "BossDespawn" && hitpoints <= 0)
        {
            Destroy(gameObject);
        }
        base.OnTriggerEnter2D(EnterredObject);

        if (EnterredObject.gameObject.name == ("SpikeTrigger") || EnterredObject.tag == "PitWall")
        {
            if (FourthPhaseReached)
            {
                transform.position = new Vector3(108.9f, -5.3f);
            }
            else if (ThirdPhaseReached)
            {
                transform.position = new Vector3(71.4f, -5.3f);
            }
            else if (SecondPhaseReached)
            {
                transform.position = new Vector3(35.6f, -5.3f);
            }
            else
            {
                transform.position = new Vector3(-3.3f, -5.3f);
            }
        }
    }
コード例 #8
0
 private bool CheckGrounded()
 {
     if (AgentRigidbody.velocity.y <= 0)  //if we are not jumping
     {
         foreach (Transform point in groundPoints)
         {
             Collider2D[] colliders = Physics2D.OverlapCircleAll(point.position, groundCollideRadius, whatIsGround);  //create colliders that check for whatIsGround (currently set to everything)
                                                                                                                      //within groundCollideRadius (set in unity) of point.position (The PC's feet and a centre point between them)
             for (int i = 0; i < colliders.Length; i++)
             {
                 if (colliders[i].gameObject != gameObject)   //if the colliders are colliding with a gameObject that is not the player (i.e. the ground)
                 {
                     AgentAnimator.ResetTrigger("Jump");
                     AgentAnimator.SetBool("Falling", false); // we have finished falling (or we never were) so tell Unity we don't need to play the animation
                     return(true);                            //then we are on the ground
                 }
             }
         }
     }
     return(false);                   //otherwise if colliders are only colliding with the player character, we must not be on the ground
 }
コード例 #9
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (Alive())
        {
            UpdateHide();
            if (!(activeState is RangedAttackState))
            {
                AgentAnimator.SetBool("Shooting", false);
            }
            PlayerNearby = LookForPlayer();

            if (!hiding)
            {
                if (!Patrol && !PlayerNearby && !(activeState is IdleState))
                {
                    SetState(new IdleState());
                }
                else if (Patrol && !PlayerNearby && !(activeState is PatrolState))
                {
                    SetState(new PatrolState());
                }
            }

            if (PlayerNearby && !IsPlayerReachable() && !(activeState is HideState))
            {
                SetState(new HideState());
                hiding = true;
            }
            else if (IsPlayerReachable() && !(activeState is RangedAttackState))
            {
                SetState(new RangedAttackState());
                hiding = false;
            }
            activeState.Act();
        }
    }
コード例 #10
0
ファイル: Boss.cs プロジェクト: gkjolin/2D-Platformer
    void FixedUpdate()
    {
        onGround = CheckGrounded();
        if (AgentRigidbody.velocity.y < 0)          //if player character is falling and not on a moving platform
        {
            AgentAnimator.SetBool("Falling", true); //play falling animation. This can't be a trigger because we are unsure how far the player character is falling and so the animation has to be played
        }                                           // until explicitly told to stop. (i.e boolean is false again)
        HandleLayers();

        myHealthBar.UpdateHealth(hitpoints, 400f);
        if (hitpoints < 300 && !SecondPhaseReached)
        {
            FirstPhase  = false;
            SecondPhase = true;
        }
        else if (hitpoints < 200 && !ThirdPhaseReached)
        {
            ThirdPhase = true;
        }
        else if (hitpoints < 100 && !FourthPhaseReached)
        {
            FourthPhase = true;
        }
        else if (hitpoints <= 0)
        {
            if (!(activeState is PhaseChangeState))
            {
                SetState(new PhaseChangeState());
            }
            activeState.Act();
            exitDoor.OpenDoor();
        }

        if (Alive())
        {
            if (FirstPhase)
            {
                PlayerNearby = LookForPlayer();
                if (SecondPhase || ThirdPhase || FourthPhase)
                {
                    if (!(activeState is PhaseChangeState))
                    {
                        SetState(new PhaseChangeState());
                    }
                }
                else if (!Patrol && !PlayerNearby && !(activeState is IdleState))
                {
                    SetState(new IdleState());                                          //can possibly remove idle and patrol states here.
                }
                else if (Patrol && !PlayerNearby && !(activeState is PatrolState))
                {
                    SetState(new PatrolState());
                }
                else if (PlayerMeleeRange() && !(activeState is MeleeAttackState))
                {
                    SetState(new MeleeAttackState());
                }
                else if (PlayerNearby && !PlayerMeleeRange() && !(activeState is ChaseState))
                {
                    SetState(new ChaseState());
                }
            }
            else
            {
                if (SecondPhase || ThirdPhase || FourthPhase)
                {
                    Debug.Log("SecondPhase : " + SecondPhase);
                    Debug.Log("ThirdPhase : " + ThirdPhase);
                    Debug.Log("FourthPhase : " + FourthPhase);

                    if (!(activeState is PhaseChangeState))
                    {
                        SetState(new PhaseChangeState());
                    }
                }
                else if (PlayerMeleeRange() && !(activeState is MeleeAttackState))
                {
                    AgentAnimator.SetBool("Throwing", false);
                    SetState(new MeleeAttackState());
                }
                else if (!(activeState is RangedAttackState))
                {
                    SetState(new RangedAttackState());
                }
            }

            activeState.Act();
        }
    }