Example #1
0
    protected void SingleShot(Ray direction)
    {
        Transform cam = gunner.GetComponentInChildren <Camera>().transform.FindChild("GunBarrell");

        direction.direction = Quaternion.Euler(Random.Range(-spreadAngle, spreadAngle), Random.Range(-spreadAngle, spreadAngle), 0) * cam.forward;
        RaycastHit info = new RaycastHit();

        if (Physics.Raycast(direction, out info, range))
        {
            GameObject target = info.transform.gameObject;

            //TracerEffect.ShowTracerEffect(cam.position + direction.direction, direction.direction, info.distance);

            ImpactEffect.ShowImpactEffect(info.point, info.normal);

            if (target.GetComponent <DamageScript>() == null)
            {
                return;
            }
            if (target.CompareTag("Enemy"))
            {
                GetComponentInParent <GunnerScript>().ShowHitTime = delay * 0.8f;
                target.GetComponent <DamageScript>().damage(damage);
            }
        }
        else
        {
            TracerEffect.ShowTracerEffect(cam.position + direction.direction, direction.direction, 100);
        }
    }
Example #2
0
    void fireCannon(Vector3 hitPos, Vector3 hitNormal, float distance)
    {
        MuzzleEffect.ShowMuzzleEffect(Cannon.transform, true, Audio);
        TracerEffect.ShowTracerEffect(Cannon.transform.position, Cannon.transform.forward, distance);

        if (hitNormal != Vector3.zero)
        {
            ImpactEffect.ShowImpactEffect(hitPos, hitNormal);
        }

        Collider[] colliders = Physics.OverlapSphere(hitPos, 2f);

        foreach (Collider c in colliders)
        {
            Rigidbody rb = c.GetComponent <Rigidbody>();

            if (rb)
            {
                rb.AddExplosionForce(600f, hitPos, 2f);
            }
        }
    }