Ejemplo n.º 1
0
 void OnTriggerEnter(Collider collider)
 {
     if (collider.gameObject.tag.Equals("Bottom"))
     {
         Debug.Log("Fall");
         ph.AdjustCurHealth(-ph.curHealth);
     }
 }
Ejemplo n.º 2
0
    void OnTriggerEnter2D(Collider2D other)     //die if hitting out of bounds or bullets or whatever. Currently, just die if hit by anything
    {
        // if hit by bullet
        if (other.gameObject.CompareTag("Bullet"))
        {
            // if player is alive then deal damage
            if (ph.curHealth > 0)
            {
                ph.AdjustCurHealth(-1);
            }
        }
        // if hit by flame
        if (other.gameObject.CompareTag("Flame"))
        {
            // if player is alive then deal damage
            if (ph.curHealth > 0)
            {
                ph.AdjustCurHealth(-2);
            }
        }
        // if the camera catches up with the player
        else if (other.gameObject.CompareTag("Death"))
        {
            ph.AdjustCurHealth(-ph.curHealth);
        }
        // if player goes through portal
        else if (other.gameObject.CompareTag("Portal"))
        {
            Vector3 end = other.transform.FindChild("Exit").transform.position;
            Debug.Log("child: " + end);
            transform.position = end;

            // move camera when Leafie teleports
            myCamera.GetComponent <MoveCamera>().OnLeafieTeleport();
        }
        // if player reaches the goal
        else if (other.gameObject.CompareTag("Goal"))
        {
            WinLoseText.text = "PLAYER 1 WINS!";
            gameOver         = true;
        }
    }
Ejemplo n.º 3
0
    private void Attack()
    {
        float distance = Vector3.Distance(target.transform.position, transform.position);

        Vector3 dir       = (target.transform.position - transform.position).normalized;
        float   direction = Vector3.Dot(dir, transform.forward);

        if (distance < 3.5f && direction > 0.6f)
        {
            PlayerHealth ph = (PlayerHealth)target.GetComponent("PlayerHealth");
            ph.AdjustCurHealth(-10);
        }
    }