using UnityEngine; using UnityEngine.Rendering.HighDefinition; public class SpawnRandomBeachBall : MonoBehaviour { public static float TimeBtwnEachBall = 0.1f; public float rangeAmplitude = 10f; public float verticalSpeedMultiplier = 5f; private float lastBeachBallSpawnedTime; private void Update() { if (Input.GetKeyDown(KeyCode.Space) && Time.realtimeSinceStartup - lastBeachBallSpawnedTime >= TimeBtwnEachBall && PoolManager.Instances[PoolManager.InstanceType.Ball] != null) { GameObject nextAvailable = PoolManager.Instances[PoolManager.InstanceType.Ball].getNextAvailable(); if (nextAvailable != null) { lastBeachBallSpawnedTime = Time.realtimeSinceStartup; nextAvailable.transform.position = new Vector3(-2.5f, 4f, -2f); nextAvailable.GetComponent().targetSurface = GetComponent(); Vector3 force = new Vector3(Random.Range(0f - rangeAmplitude, rangeAmplitude), 0f - Random.Range(0f, verticalSpeedMultiplier * rangeAmplitude), Random.Range(0f - rangeAmplitude, rangeAmplitude)); nextAvailable.SetActive(value: true); nextAvailable.GetComponent().AddForce(force, ForceMode.Impulse); } } } }