void Shoot()
    {
        timer = 0f;

        gunAudio.Play();

        gunLine.enabled = true;
        gunLine.SetPosition(0, transform.position);

        shootRay.origin    = transform.position;
        shootRay.direction = transform.forward;

        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            NormalAgentGame NA = shootHit.collider.GetComponent <NormalAgentGame>();
            if (NA != null)
            {
                NA.TakeDamageFromPlayer(damagePerShot, this);
            }

            gunLine.SetPosition(1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
    }
 public void TakeDamage(float damage, NormalAgentGame NAG)
 {
     //Debug.Log(this + " Take " + damage + " damage from: " + NAG);
     //AddReward(-0.2f);
     regenTimer = 0f; // reset the timer
     if (isCheating)
     {
         damage = 0f;
     }
     currentHealth -= damage;
     if (currentHealth <= 0)
     {
         RegisterDeath();
         NAG.RegisterKill();
     }
 }
Exemple #3
0
    public void TakeDamage(float amout, NormalAgentGame NAG)
    {
        isDamaged      = true; // set the damaged flag to true
        regenTimer     = 0f;   // reset the timer to regenerate health
        currentHealth -= amout;

        playerAudio.Play(); // play the hurt sound efx

        SetHealthUI();

        if (currentHealth <= 0 && !isDead)
        {
            NAG.RegisterKill();
            Death();
        }
    }
    void Shoot()
    {
        shootTimer      = 0f;
        gunLine.enabled = true;
        gunAudio.Play();
        gunLine.SetPosition(0, shootingPoint.position);
        shootRay.origin    = shootingPoint.position;
        shootRay.direction = transform.forward;

        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            NormalAgentGame normalAgentGame = shootHit.collider.GetComponent <NormalAgentGame>();
            PlayerHealth    playerHealth    = shootHit.collider.GetComponent <PlayerHealth>();
            if (normalAgentGame != null)
            {
                //Debug.Log("Hit!");
                //AddReward(0.33f);
                if (isCheating)
                {
                    damagePerShot = cheatDamagePerShot;
                }
                normalAgentGame.TakeDamage(damagePerShot, this); // Harming other agents
            }
            else if (playerHealth != null)
            {
                if (isCheating)
                {
                    damagePerShot = cheatDamagePerShot;
                }
                playerHealth.TakeDamage(damagePerShot, this); // Harming player
            }
            else
            {
                //Debug.Log("Missed!");
                //AddReward(-0.1f);
            }

            gunLine.SetPosition(1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
            //Debug.Log("Missed!");
        }
    }