Ejemplo n.º 1
0
    private void DoShoot()
    {
        BounceRay hit = BounceRay.Cast(playerController.transform.position, gmousePos - playerController.transform.position, 10.0f, LayerMask.GetMask("Bounceable"), LayerMask.GetMask("Actor"));

        hitPoints = hit.endPoints;

        Vector2 prevPoint = playerController.transform.position;

        int visorIndex = 0;

        foreach (Vector2 endPoint in hit.endPoints)
        {
            int count = Mathf.FloorToInt((endPoint - prevPoint).magnitude / 0.1f);

            for (int i = 0; i < count; i++)
            {
                visors[visorIndex].transform.position = Vector2.Lerp(prevPoint, endPoint, (float)i / count);
                visorIndex++;
            }

            for (int i = visorIndex; i < 100; i++)
            {
                visors[i].transform.position = new Vector3(1000, 1000, 0);
            }

            prevPoint = endPoint;
        }
    }
Ejemplo n.º 2
0
    public List <HitPackage> Shoot(bool justDraw = false)
    {
        if (!shootingCooldown.IsOver())
        {
            return(null);  // TODO: aca podria indicarle al usuario que no puede disparar todavia (o mostrar en la UI el remaining cooldown)
        }
        shootingCooldown.RestartCooldown();

        Debug.Log($"shooting {shootingCooldown.RemainingCooldown()}");

        // Draw bullet
        var _transform = GO.transform;
        var bullet     = new Bullet(_transform.position, _transform.forward, _transform.rotation);

        bullet.Cast();
        if (justDraw)
        {
            return(null);
        }

        // Calculate bullet's bounces
        Vector3 originRay = _transform.position + _transform.forward * 0.6f;
        var     bounceRay = BounceRay.Cast(originRay, _transform.forward, gunRange);

        if (bounceRay.contacts.Count != 0)
        {
            var hitPackages = new List <HitPackage>();
            bounceRay.contacts.ForEach(c =>
            {
                hitPackages.Add(new HitPackage(c.transform.name, gunDamage));
                Debug.Log($"shot {c.transform.name}");
            });
            return(hitPackages);
        }

        // Old single ray implementation
        // RaycastHit hit;
        // var ray = new Ray(originRay, _transform.forward);
        // if (Physics.Raycast(ray, out hit, gunRange))
        // {
        //     Debug.Log($"shot {hit.transform.name}");
        //     return new HitPackage(hit.transform.name, gunDamage);
        // }

        return(null);
    }
Ejemplo n.º 3
0
    private IEnumerator ShootRoutine()
    {
        playerController.controllable = false;
        customCursor.active           = false;

        Vignette vignette = postProcessProfile.GetSetting <Vignette>();

        breath.PlayOneShot(breaths[Random.Range(0, breaths.Count - 1)]);



        float currTime = 0.0f;

        while (currTime < 0.8f)
        {
            float progress = currTime / 0.8f;

            //mainTrack.pitch = EaseOutQuad(1.0f, 0.5f, progress);
            float freq = EaseOutQuad(22000.0f, 600.0f, progress);
            mainTrackLowPass.cutoffFrequency = freq;
            foreach (AudioLowPassFilter audioSource in lowPassLayers)
            {
                audioSource.cutoffFrequency = freq;
            }


            rainLowPass.cutoffFrequency = EaseOutQuad(22000.0f, 600.0f, progress);
            Time.timeScale = EaseOutQuad(1.0f, 0.1f, progress);
            vignette.intensity.Override(EaseOutQuad(0.1f, 0.3f, progress));

            foreach (SpriteRenderer visor in visors)
            {
                visor.color = Color32.Lerp(new Color32(255, 255, 255, 255), new Color32(255, 255, 255, 0), progress);
            }

            currTime += Time.unscaledDeltaTime;

            yield return(null);
        }
        mainTrackLowPass.cutoffFrequency = 600.0f;
        foreach (AudioLowPassFilter audioSource in lowPassLayers)
        {
            audioSource.cutoffFrequency = 600.0f;
        }
        rainLowPass.cutoffFrequency = 600.0f;
        //mainTrack.pitch = 0.5f;
        Time.timeScale = 0.1f;
        vignette.intensity.Override(0.3f);
        foreach (SpriteRenderer visor in visors)
        {
            visor.color = new Color32(255, 255, 255, 0);
        }

        BounceRay hit = BounceRay.Cast(playerController.transform.position, gmousePos - playerController.transform.position, 10.0f, LayerMask.GetMask("Bounceable"), LayerMask.GetMask("Actor"));

        hitPoints = hit.endPoints;

        targetActor = null;
        if (hit.hit != null && ((RaycastHit2D)hit.hit).collider != null)
        {
            Actor actor = ((RaycastHit2D)hit.hit).collider.GetComponent <Actor>();
            targetActor = actor;

            if (targetActor.isTarget)
            {
                wasHit = true;
            }
        }

        gunshot.Play();
        bullet         = Instantiate(bulletPrefab, playerController.transform.position, Quaternion.identity);
        bulletParticle = Instantiate(bulletParticlePrefab, playerController.transform.position, Quaternion.identity);

        StartCoroutine(BulletKill());

        yield return(StartCoroutine(Delay(0.2f, true)));

        currTime = 0.0f;
        while (currTime < 0.5f)
        {
            float progress = currTime / 0.5f;


            //mainTrack.pitch = EaseOutQuad(0.5f, 1.0f, progress);
            float freq = EaseOutQuad(600.0f, 22000.0f, progress);
            mainTrackLowPass.cutoffFrequency = freq;
            foreach (AudioLowPassFilter audioSource in lowPassLayers)
            {
                audioSource.cutoffFrequency = freq;
            }
            rainLowPass.cutoffFrequency = EaseOutQuad(600.0f, 22000.0f, progress);
            Time.timeScale = EaseOutQuad(0.1f, 1.0f, progress);
            vignette.intensity.Override(EaseOutQuad(0.3f, 0.1f, progress));

            currTime += Time.unscaledDeltaTime;

            yield return(null);
        }
        mainTrackLowPass.cutoffFrequency = 22000.0f;
        foreach (AudioLowPassFilter audioSource in lowPassLayers)
        {
            audioSource.cutoffFrequency = 22000.0f;
        }
        rainLowPass.cutoffFrequency = 22000.0f;
        //mainTrack.pitch = 1.0f;
        Time.timeScale = 1.0f;
        vignette.intensity.Override(0.1f);
    }