Beispiel #1
0
    private void Shoot()
    {
        Debug.Log("Fire!");

        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))
        {
            Debug.Log("Hostile inbound!");
            AbsHostile hostile = shootHit.collider.GetComponent <AbsHostile>();
            if (hostile != null)
            {
                hostile.TakeDamage(damage);
            }
            AbsLoot loot = shootHit.collider.GetComponent <AbsLoot>();
            Debug.Log("Loot is: " + loot);
            if (loot != null)
            {
                loot.Push(shootRay.direction);
            }

            gunLine.SetPosition(1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
    }