using System.Collections; using System.Collections.Generic; using UnityEngine; public…
- User
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Chest : MonoBehaviour { public float delayTime = 5f; public GameObject bowPrefab; public GameObject healthPickupPrefab;
private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Player")) { // Generate a random number (between 0 and 1) to determine if bow spawns or not float randomValue = Random.value; float randomValue2 = Random.value; if (randomValue <= 0.5f) { // Spawn a bow GameObject bow = Instantiate(bowPrefab, collision.transform); bow.transform.localPosition = new Vector3(-0.25f, -0.25f, 0f); bow.transform.localRotation = Quaternion.identity; } if (randomValue2 <= 0.3f) { // Spawn a HealthPickup GameObject healthPickup = Instantiate(healthPickupPrefab); healthPickup.transform.localPosition = transform.position; healthPickup.transform.localRotation = Quaternion.identity; } // Disable the chest to prevent spawning multiple bows gameObject.SetActive(false); // Enable the chest after a delay Invoke("EnableChest", delayTime); } } private void EnableChest() { gameObject.SetActive(true); }} make it so if the current scene index is 0 then spawns the bow, but if the current scene index is 1 then it spawns a pistol
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.