void Attack()
    {
        timer = 0f;

        if (playerHealth.currentHealth > 0)
        {
            Debug.Log(this.gameObject.name);
            playerHealth.TakeDamage(attackDamage);
        }
    }
コード例 #2
0
 public void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject == player)
     {
         print("healed");
         if (playerHealth.currentHealth < playerHealth.startingHealth)
         {
             playerHealth.TakeDamage(-25);
         }
         Destroy(this.gameObject);
     }
 }
コード例 #3
0
    void Shoot()
    {
        shooting = true;

        // The fractional distance from the player, 1 is next to the player, 0 is the player is at the extent of the sphere collider.
        float fractionalDistance = (col.radius - Vector3.Distance(transform.position, player.position)) / col.radius;

        // The damage is the scaled damage, scaled by the fractional distance, plus the minimum damage.
        float damage = scaledDamage * fractionalDistance + minimumDamage;

        shootRay.origin    = laserShotLine.transform.position;
        shootRay.direction = player.transform.position - transform.position;

        laserShotLine.SetPosition(0, laserShotLine.transform.position);

        if (Physics.Raycast(shootRay, out shootHit, range))
        {
            PlayerHealth2 playerHealth = shootHit.collider.GetComponent <PlayerHealth2> ();

            if (playerHealth != null)
            {
                playerHealth.TakeDamage(damage);
            }
            laserShotLine.SetPosition(1, shootHit.point);
        }
        else
        {
            laserShotLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }

        //laserShotLine.SetPosition(1, player.position + Vector3.up * 1.5f);

        laserShotLine.enabled = true;

        laserShotLight.intensity = flashIntensity;

        AudioSource.PlayClipAtPoint(shotClip, laserShotLight.transform.position);
    }
コード例 #4
0
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Boundary")
        {
            Destroy(gameObject);
        }


        if (other.tag == "Player2")
        {
            player2.TakeDamage(10);

            Destroy(gameObject);
        }



        if (other.tag == "Player2Shot")
        {
            Instantiate(explosion, transform.position, transform.rotation);
            Destroy(gameObject);
        }
    }