コード例 #1
0
 void ShootInDirection(Vector3 direction)
 {
     for (int i = 0; i < bulletOrigins.Length; i++)
     {
         Vector3 randomOffset    = Random.insideUnitSphere * weaponSpread;
         Vector3 flattenedOffset = Vector3.Scale(randomOffset, bulletDirectionScale);
         bulletPool.NewBullet(bulletOrigins[i].transform.position, direction + flattenedOffset);
     }
 }
コード例 #2
0
    void Update()
    {
        if (Time.timeScale > 0f)
        {
            if (Input.GetKeyDown(KeyCode.M))
            {
                useFastBullets = !useFastBullets;                                               //TODO remove this. its just for testing
            }
            if (Input.GetKeyDown(KeyCode.N))
            {
                useIncreasedFireRate = !useIncreasedFireRate;
            }

            if (playerInput.GetFireInput())
            {
                if (Time.time > nextShot)
                {
                    if (useFastBullets)
                    {
                        fastBulletPool.NewBullet(transform.position, GetBulletDirection());
                    }
                    else
                    {
                        normalBulletPool.NewBullet(transform.position, GetBulletDirection());
                    }
                    if (useIncreasedFireRate)
                    {
                        nextShot = Time.time + (1f / increasedFireRate);
                    }
                    else
                    {
                        nextShot = Time.time + (1f / normalFireRate);
                    }
                }
            }
            if (playerInput.GetSpecialInputDown())
            {
                if (!specialWeapon.IsEmpty())
                {
                    if (specialWeapon.CanFire())
                    {
                        specialWeapon.Fire();
                        gui.SetSPWAmmoNumber(specialWeapon.GetAmmoCount());
                        gui.SetSPWDisplayState(false);
                    }
                    else
                    {
                        //TODO uisounds.playerrorsound() or something like that
                        Debug.Log("wait");
                    }
                }
                else
                {
                    //TODO uisounds.playerrorsound() or something like that
                    Debug.Log("empty");
                }
            }
            gui.SetSPWAmmoNumber(specialWeapon.GetAmmoCount());
            gui.SetSPWDisplayState(specialWeapon.CanFire());
        }
    }