Ejemplo n.º 1
0
 public void Activate()
 {
     if (currentState == Enemy4State.Inactive)
     {
         currentState = Enemy4State.Activated;
     }
 }
Ejemplo n.º 2
0
 public void Death()
 {
     gm.score += scoreWorth;
     gm.UpdateScore();
     currentState = Enemy4State.Dead;
     fabCtrl.PlaySoundEnemy1Destroyed();
     GetComponent <SpriteRenderer>().enabled   = false;
     GetComponent <CircleCollider2D>().enabled = false;
     dp.DeathFX();
     //gameObject.SetActive(false);
 }
Ejemplo n.º 3
0
 void OnTriggerEnter2D(Collider2D c)
 {
     if (c.gameObject.tag == "Player")
     {
         int dir;
         if (c.transform.position.x < transform.position.x)
         {
             dir = -1;
         }
         else
         {
             dir = 1;
         }
         if (ps.canTakeDamage)
         {
             ps.EnemyHitPlayer(dir);
             targetPosSet = false;
             currentState = Enemy4State.Recover;
         }
     }
 }
Ejemplo n.º 4
0
    void Update()
    {
        if (currentState == Enemy4State.Inactive || currentState == Enemy4State.Dead)
        {
            return;
        }
        if (gm.currentState != GameState.Running)
        {
            return;
        }
        if (ps.currentState == PlayerState.Dead)
        {
            return;
        }

        playerPos = player.transform.position;
        pos       = transform.position;

        if (GetComponent <Rigidbody2D>().velocity.x < 0)
        {
            hDir = -1;
        }
        else if (GetComponent <Rigidbody2D>().velocity.x > 0)
        {
            hDir = 1;
        }

        if (playerPos.x < pos.x)
        {
            spriteRenderer.flipX = true;
        }
        if (playerPos.x > pos.x)
        {
            spriteRenderer.flipX = false;
        }

        if (Input.GetKeyDown(KeyCode.F))
        {
            GetComponent <SpriteRenderer>().flipX = GetComponent <SpriteRenderer>().flipX ? false : true;
        }

        if (Mathf.Abs(pos.x - playerPos.x) <= triggerDistance && currentState == Enemy4State.Activated && currentState != Enemy4State.Awake)
        {
            currentState = Enemy4State.Awake;
        }

        if (currentState == Enemy4State.Awake)
        {
            if (!targetPosSet)
            {
                usedSpeed    = speed;
                targetPos    = new Vector3((pos.x + 2 * hDir), pos.y + 2, 0);
                targetPosSet = true;
            }
            if (targetPosSet)
            {
                Move();
            }
            if ((targetPos - pos).magnitude < 0.1f)
            {
                targetPosSet = false;
                currentState = Enemy4State.Dive;
            }
        }

        if (currentState == Enemy4State.Dive)
        {
            if (!targetPosSet)
            {
                usedSpeed    = diveSpeed;
                targetPos    = playerPos;
                targetPosSet = true;
            }
            if (targetPosSet)
            {
                Move();
            }
            if ((targetPos - pos).magnitude < 0.1f)
            {
                targetPosSet = false;
                currentState = Enemy4State.Recover;
            }
        }

        if (currentState == Enemy4State.Recover)
        {
            if (!targetPosSet)
            {
                usedSpeed    = backOffSpeed;
                targetPos    = new Vector3((pos.x + 4 * hDir), pos.y + 4, 0);
                targetPosSet = true;
                if (hDir == -1)
                {
                    hDir = 1;
                }
                else
                {
                    hDir = -1;
                }
            }
            if (targetPosSet)
            {
                Move();
            }
            if ((targetPos - pos).magnitude < 0.1f)
            {
                targetPosSet = false;
                currentState = Enemy4State.Dive;
            }
        }
    }