Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        time += Time.deltaTime;

        if (cooldownCounter > 0f)
        {
            cooldownCounter -= Time.deltaTime;
        }

        if (turretController.active == true && time >= fireRate)
        {
            if (turretController.IsWithinFireRange())
            {
                if (cooldownCounter <= 0f)
                {
                    GameObject shot = Instantiate(bulletPrefab, spawnLocation.position, spawnLocation.rotation);
                    SoundManager.PlaySound(SoundManager.Sound.TurrenLazerShotFire, transform.position);
                    Destroy(shot, 120f);
                    Debug.Log("Click clack");
                    Rigidbody rb = shot.GetComponent <Rigidbody>();
                    rb.velocity     = -turretController.turretHead.up * bulletSpeed;
                    cooldownCounter = cooldown;

                    //resets turets firerate
                    fireRate = Random.Range(minimumDelay, maximumDelay);
                    time     = 0;
                }
            }
            else
            {
                Debug.Log("Not inside fire area");
            }
        }
    }