Ejemplo n.º 1
0
 void Awake()
 {
     player         = GameObject.FindGameObjectWithTag("Player");
     playerHealthHU = player.GetComponent <PlayerHealthHU> ();
     enemyHealthHU  = GetComponent <EnemyHealthHU>();
     anim           = GetComponent <Animator> ();
 }
 void Awake()
 {
     player         = GameObject.FindGameObjectWithTag("Player").transform;
     playerHealthHU = player.GetComponent <PlayerHealthHU> ();
     enemyHealthHU  = GetComponent <EnemyHealthHU> ();
     nav            = GetComponent <NavMeshAgent>();
     body           = GetComponent <Rigidbody>();
 }
Ejemplo n.º 3
0
    void Shoot()
    {
        timer = 0f;

        gunAudio.Play();

        gunLight.enabled = true;

        gunParticles.Stop();
        gunParticles.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))
        {
            if (shootHit.collider.gameObject.tag.Equals("Enemy"))
            {
                EnemyHealthHU enemyHealthHU = shootHit.collider.GetComponent <EnemyHealthHU>();
                if (enemyHealthHU != null)
                {
                    enemyHealthHU.TakeDamage(damagePerShot, shootHit.point);
                }

                NavMeshAgent agent = shootHit.collider.GetComponent <NavMeshAgent>();
                Rigidbody    body  = shootHit.collider.GetComponent <Rigidbody>();
                agent.enabled    = false;
                body.isKinematic = true;
                body.AddForce(-shootRay.direction.normalized * 10, ForceMode.Impulse);
            }
            else
            {
                Instantiate(shootMetalAnimation, shootHit.point, Quaternion.identity);
            }
            gunLine.SetPosition(1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
    }