void OnTriggerEnter2D(Collider2D col)
 {
     if (col.tag == "Shot")
     {
         ShotAttributes shot = col.GetComponent <ShotAttributes> ();
         if (shot.getTeamID() != teamID)
         {
             takeDamage(shot.damage);
             Destroy(col.gameObject);
         }
     }
 }
Exemple #2
0
    private void fireShot()
    {
        Vector3        direction = getFireDirection();
        float          angle     = transform.rotation.eulerAngles.z;
        GameObject     newShot   = Instantiate(shot, transform.Find("Weapon").transform.position, Quaternion.Euler(new Vector3(0.0f, 0.0f, angle)));
        ShotAttributes shotAtt   = newShot.GetComponent <ShotAttributes> ();

        shotAtt.setTeamID(teamID);
        shotAtt.setPlayerID(playerID);
        Rigidbody2D shotRigidbody2D = newShot.GetComponent <Rigidbody2D> ();

        shotRigidbody2D.velocity = direction * shotSpeed;
    }
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.tag == "Shot")
     {
         // TO DO: really figure out what is the best way to structure the rigidbody and collider of the shot, wither in the parent shot or in the child bullet,
         // especially if I decide to work with reflections
         ShotAttributes shot = col.GetComponent <ShotAttributes> ();
         if (shot.getTeamID() != teamID && !shot.energy)
         {
             print("Shot with ID " + shot.getTeamID() + " collided with wall with team ID " + teamID);
             Destroy(col.gameObject);
         }
     }
     if (col.tag == "Ghost" && !ghostTrespassable)
     {
         GhostController ghostController = col.GetComponent <GhostController> ();
         ghostController.collidesWithBoundary();
     }
 }
    //TODO: Implement grace period. Righ now, using OnTriggerEnter, boss can park on top of a cornered player, and using OnTriggerStay, boss insta-kills him
    void OnTriggerStay2D(Collider2D col)
    {
        if (col.tag == "Shot")
        {
            ShotAttributes shot = col.GetComponent <ShotAttributes> ();
            if (shot.getTeamID() != teamID)
            {
                if (!onGracePeriod())
                {
                    takeDamage(shot.damage);
                    timeLastDamage = Time.time;
                }
                Destroy(col.gameObject);
            }
        }

        if (col.tag == "Pickup")
        {
            HealthPickup healthPickup = col.GetComponent <HealthPickup> ();
            currentHealth += healthPickup.healthRecovered;
            if (currentHealth > maxHealth)
            {
                currentHealth = maxHealth;
            }
            healthTracker.setHealth(currentHealth);
            Destroy(col.gameObject);
        }

        if (col.tag == "Boss" && !onGracePeriod())
        {
            takeDamage(1);
            isStunned       = true;
            timeRecoverStun = Time.time + timeStunned;

            Vector3 offset    = transform.position - col.transform.position;
            Vector3 direction = offset.normalized;
            rb.velocity = direction * speedStunned;

            timeLastDamage = Time.time;
        }
    }
Exemple #5
0
    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.tag == "Shot")
        {
            ShotAttributes shot = col.GetComponent <ShotAttributes> ();
            if (shot.getTeamID() != teamID)
            {
                takeDamage(shot.damage);
                Destroy(col.gameObject);
            }
        }

        if (col.tag == "Pickup")
        {
            HealthPickup healthPickup = col.GetComponent <HealthPickup> ();
            currentHealth += healthPickup.healthRecovered;
            if (currentHealth > maxHealth)
            {
                currentHealth = maxHealth;
            }
            healthTracker.setHealth(currentHealth);
            Destroy(col.gameObject);
        }
    }