Exemplo n.º 1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (count < 0)
        {
            count = Mathf.RoundToInt(fireRate / Time.fixedDeltaTime);

            if (Input_scr.OnFire())
            {
                GameObject a      = Instantiate(bulletPrefab);
                Vector3    offset = new Vector3(Mathf.Cos((transform.localEulerAngles.z + 90) * Mathf.Deg2Rad), Mathf.Sin((transform.localEulerAngles.z + 90) * Mathf.Deg2Rad), 0);
                a.transform.position = transform.position + offset;

                a.transform.localEulerAngles = transform.localEulerAngles + new Vector3(0, 0, Random.Range(-bulletSpread, bulletSpread));
                a.GetComponent <Bullet_scr>().startVelocity = GetComponent <Rigidbody2D>().velocity;
                a.GetComponent <Bullet_scr>().owner         = gameObject;
                a.GetComponent <Bullet_scr>().speed         = bulletSpeed;
                cam.GetComponent <Camera_scr>().ShakePosition(0.5f, 0.4f, 0, 1);
                GetComponent <AudioSource>().Play();

                transform.position -= new Vector3(Mathf.Cos((transform.localEulerAngles.z + 90) * Mathf.Deg2Rad), Mathf.Sin((transform.localEulerAngles.z + 90) * Mathf.Deg2Rad), 0) * 0.2f;
            }
            else
            {
            }
        }
        count--;
    }
Exemplo n.º 2
0
    new void Update()
    {
        base.Update();
        if (active == false)
        {
            return;
        }

        if (Input_scr.OnFire() && count < 0)
        {
            count = Mathf.RoundToInt(fireRate / Time.deltaTime);
            ammo--;
            RaycastHit hit;

            if (Physics.Raycast(cam.transform.position + cam.transform.forward * 1, cam.transform.forward, out hit))
            {
                if (hit.transform.tag == "Solid")
                {
                    GameObject a = Instantiate(hitSplashPrefab);
                    a.transform.position = hit.point;
                }
                else
                if (hit.transform.tag == "Enemy")
                {
                    hit.transform.GetComponent <Enemy_scr>().DoDamage(10);
                }
            }

            // Juice
            aud.Play();

            transform.localEulerAngles += new Vector3(0, 0, 20);
            transform.localPosition    += new Vector3(0, 0, -0.2f);

            StartCoroutine(Flash());
            cam.GetComponent <Camera_scr>().Shake(0.4f);
            effects.Flash(Color.white * 0.5f, 0.5f);
        }
        count--;
    }
Exemplo n.º 3
0
    void FixedUpdate()
    {
        if (multiplierCooldown > 0)
        {
            multiplierCooldown--;
        }
        else
        {
            multiplier = 1;
        }
        multiplier         = Mathf.Clamp(multiplier, 1, maxMultiplier);
        multiplierCooldown = Mathf.Clamp(multiplierCooldown, 0, maxMultiplierCooldown);

        if (healthRegenRateCount < 0)
        {
            healthRegenRateCount = Mathf.RoundToInt(healthRegenRate / Time.fixedDeltaTime);
            if (health < maxHealth && healthRegenCooldownCount < 0)
            {
                health++;
            }
        }

        healthRegenCooldownCount--;
        healthRegenRateCount--;

        particles.transform.localEulerAngles = new Vector3(0, 0, Mathf.LerpAngle(particles.transform.localEulerAngles.z, particlesAngle, 0.1f));

        // Steering
        if (Input_scr.OnLeft())
        {
            rigid.AddTorque(turnSpeed);
            particlesAngle = -30;
        }
        else
        if (Input_scr.OnRight())
        {
            rigid.AddTorque(-turnSpeed);
            particlesAngle = 30;
        }
        else
        {
            rigid.angularVelocity = 0;
            particlesAngle        = 0;
        }

        // Movement
        if (Input_scr.OnThrottle())
        {
            rigid.AddForce(transform.up * acceleration);
            particlesEM.enabled = true;
            GetComponents <AudioSource>()[1].mute = false;

            if (GetComponents <AudioSource>()[1].pitch > 0.8f)
            {
                GetComponents <AudioSource>()[1].pitch -= 0.02f;
            }
        }
        else
        {
            turnSpeedMultiplier = 1;
            particlesEM.enabled = false;
            GetComponents <AudioSource>()[1].mute  = true;
            GetComponents <AudioSource>()[1].pitch = 1.6f;
        }
        if (Input_scr.OnThrottle() == false && rigid.velocity.magnitude > 10)
        {
            rigid.AddForce(-rigid.velocity * 0.5f);
        }

        if (Input_scr.OnThrottle())
        {
            turnSpeedMultiplier = turnMultiplier;
        }
        else
        if (Input_scr.OnFire())
        {
            turnSpeedMultiplier = 0.8f;
        }
        else
        {
            turnSpeedMultiplier = 1f;
        }

        // Constraints
        rigid.angularVelocity = Mathf.Clamp(rigid.angularVelocity, -maxTurnSpeed * turnSpeedMultiplier, maxTurnSpeed * turnSpeedMultiplier);
        if (rigid.velocity.magnitude > maxSpeed)
        {
            rigid.AddForce(-rigid.velocity * deceleration);
        }
    }