Beispiel #1
0
 void Awake()
 {
     astronautPlayer = GameObject.FindGameObjectWithTag("AstronautPlayer").transform;
     playerHealth    = astronautPlayer.GetComponent <PlayerHealth> ();
     alienHealth     = GetComponent <ShortAlienHealth> ();
     nav             = GetComponent <UnityEngine.AI.NavMeshAgent> ();
 }
Beispiel #2
0
    void Shoot()
    {
        timer = 0f;

        gunAudio.Play();
        gunParticles.Stop();
        gunParticles.Play();

        gunLine.enabled = true;
        gunLine.SetPosition(0, transform.position);
        shootRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        //shootRay.origin = transform.position;
        //shootRay.direction = transform.forward;

        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            AlienOneHealth alienHealth = shootHit.collider.GetComponent <AlienOneHealth> ();
            if (alienHealth != null)
            {
                alienHealth.TakeDamage(damagePerShot, shootHit.point);
            }

            ShortAlienHealth shortHealth = shootHit.collider.GetComponent <ShortAlienHealth>();
            if (shortHealth != null)
            {
                shortHealth.TakeDamage(damagePerShot, shootHit.point);
            }

            LogHealth logHealth = shootHit.collider.GetComponent <LogHealth>();
            if (logHealth != null)
            {
                logHealth.TakeDamage(damagePerShot, shootHit.point);
            }

            SpawnHealth spawnHealth = shootHit.collider.GetComponent <SpawnHealth>();
            if (spawnHealth != null)
            {
                spawnHealth.TakeDamage(damagePerShot, shootHit.point);
            }
            gunLine.SetPosition(1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
    }