31 lines
1.2 KiB
C#
31 lines
1.2 KiB
C#
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<Buoyancy>().targetSurface = GetComponent<WaterSurface>();
|
|
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<Rigidbody>().AddForce(force, ForceMode.Impulse);
|
|
}
|
|
}
|
|
}
|
|
}
|