Ejemplo n.º 1
0
    float timer;                                // Timer for counting up to the next attack.


    void Awake()
    {
        // Setting up the references.
        player       = GameObject.FindGameObjectWithTag("Player");
        playerHealth = player.GetComponent <PlayerHealth>();
        enemyHealth  = GetComponent <EnnemyHealth>();
        anim         = GetComponent <Animator>();
    }
Ejemplo n.º 2
0
 void Awake()
 {
     // Set up the references.
     player       = GameObject.FindGameObjectWithTag("Player").transform; //Pas opti
     playerHealth = player.GetComponent <PlayerHealth>();
     enemyHealth  = GetComponent <EnnemyHealth>();
     //nav = GetComponent<NavMeshAgent>();
     enemyRigidBody = GetComponent <Rigidbody>();
 }
Ejemplo n.º 3
0
 // Start is called before the first frame update
 void Start()
 {
     EnnemiAnnimator = GetComponent <Animator>();
     health          = GetComponent <EnnemyHealth>();
 }
Ejemplo n.º 4
0
    public void Shoot()
    {
        if (timer < timeBetweenBullets)
        {
            return;
        }
        // Reset the timer.
        timer = 0f;

        // Play the gun shot audioclip.
        gunAudio.Play();

        // Enable the light.
        //gunLight.enabled = true;

        // Stop the particles from playing if they were, then start the particles.
        gunParticles.Stop();
        gunParticles.Play();

        // Enable the line renderer and set it's first position to be the end of the gun.
        gunLine.enabled = true;
        gunLine.SetPosition(0, transform.position);

        // Set the shootRay so that it starts at the end of the gun and points forward from the barrel.
        shootRay.origin    = transform.position;
        shootRay.direction = transform.forward;

        // Perform the raycast against gameobjects on the shootable layer and if it hits something...
        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            // Try and find an EnemyHealth script on the gameobject hit.
            EnnemyHealth enemyHealth = shootHit.collider.GetComponent <EnnemyHealth>();

            // If the EnemyHealth component exist...
            if (enemyHealth != null)
            {
                // ... the enemy should take damage.
                enemyHealth.TakeDamage(damagePerShot, shootHit.point);
            }

            // Set the second position of the line renderer to the point the raycast hit.
            gunLine.SetPosition(1, shootHit.point);
        }
        // If the raycast didn't hit anything on the shootable layer...
        else
        {
            // ... set the second position of the line renderer to the fullest extent of the gun's range.
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }

        return;

        RaycastHit[] hits = Physics.RaycastAll(transform.position, transform.forward, range);

        if (hits.Length > 0)
        {
            // Set the second position of the line renderer to the point the raycast hit.
            gunLine.SetPosition(1, hits[hits.Length - 1].point);
            foreach (RaycastHit hit in hits)
            {
                // Try and find an EnemyHealth script on the gameobject hit.
                EnnemyHealth enemyHealth = hit.collider.GetComponent <EnnemyHealth>();

                // If the EnemyHealth component exist...
                if (enemyHealth != null)
                {
                    // ... the enemy should take damage.
                    enemyHealth.TakeDamage(damagePerShot, hit.point);
                }
            }
        }
        else
        {
            // ... set the second position of the line renderer to the fullest extent of the gun's range.
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
    }
Ejemplo n.º 5
0
 // Update is called once per frame
 private void Start()
 {
     EnnemiAnnimator = GetComponent <Animator>();
     health          = GetComponent <EnnemyHealth>();
     shoot           = GetComponent <EnnemyShoot>();
 }