using UnityEngine; public class RespawnFruit2D : 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, 0f - Random.value, 0f)); if ((bool)gameObject.GetComponent()) { gameObject.GetComponent().velocity = new Vector2(0f, velocityY); gameObject.GetComponent().AddTorque(Random.Range(-15, 15)); } float value = Random.value; gameObject.transform.localScale += new Vector3(value, value, value); Object.Destroy(gameObject, 5f); maxTimeRespawn = Time.time + (float)Random.Range(0, 3); } } }