Files
2026-03-04 10:03:45 +08:00

30 lines
976 B
C#

using UnityEngine;
public class RespawnFruit : MonoBehaviour
{
public float velocityY = 10f;
public float width = 1f;
public float maxTimeRespawn = 3f;
public GameObject[] Fruits;
public void Update()
{
if (Time.time > maxTimeRespawn)
{
GameObject gameObject = Object.Instantiate(Fruits[Random.Range(0, Fruits.Length)], base.transform.position + new Vector3(Random.Range(0f - width, width), 0f, 0f), new Quaternion(Random.value, Random.value, Random.value, Random.value));
if ((bool)gameObject.GetComponent<Rigidbody>())
{
gameObject.GetComponent<Rigidbody>().velocity = new Vector3(0f, velocityY, 0f);
gameObject.GetComponent<Rigidbody>().AddTorque(new Vector3(Random.Range(-50, 50), Random.Range(-50, 50), Random.Range(-50, 50)));
}
float value = Random.value;
gameObject.transform.localScale += new Vector3(value, value, value);
Object.Destroy(gameObject, 5f);
maxTimeRespawn = Time.time + (float)Random.Range(0, 3);
}
}
}