I will share 3 scripts consisting of a puzzle. In the PlayerInteraction script, instead…
- User
I will share 3 scripts consisting of a puzzle. In the PlayerInteraction script, instead of pressing E to call the Interact() function, i want to press E to call a UI function in which I loop through my player inventory and list all of the name items containing the EldritchSymbol component. When the player click on one of the available item in the list, then it will call the Interact() function, and the player will place the item he clicked on under the current symbol transform. Also, I need anothe OnGUI function that list the name of the item in the symbol slot, and when the player clicks it, it returns back to the player inventory. I want the GUI to be center screen. Je vais partager 3 scripts pour un puzzle dans Unity et ma propre méthode pour vérifier l'inventaire du joueur et ajouté un item dans l'inventaire. Dans ce puzzle, j'aimerais pouvoir modifier la manière que le joueur place un symbol. Dans un GUI centré dans l'écran, en vérifiant si un des 5 items comprenant la composante EldritchSymbol est dans l'inventaire, je veux que le joueur puisse lui-meme choisir l'item à placer dans le symbolSlot transform. J'aimerais aussi modifier la manière que le joeur Remove un symbol. Je veux qu'un nouveau GUI toujours centré montre le symbol actuellement placé, et qu'en cliquant sur le bouton, le joueur enlève le symbol, laissant le symbol transform vierge, puis l'item retourne dans l'inventaire du joueur. Donc, pour résumer. Changer la manière de placer et d'enlever un symbole en utilisant des GUI centré dans l'écran, pour placer un symbol il faut chercher dans l'inventaire du joueur si un item possède un symbol, puis placé cet item sur le symbol transform en pleine interaction. Pour enlever un symbole, le GUI change et montre le symbol actuellement placé sur le symbol transform, le joueur peut retirer le symbol du symbol transform et l'item retourne dans l'inventaire du joueur. Script 1: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class LovecraftianPuzzle : MonoBehaviour { public enum EldritchSymbols { Nyarlathotep, Azathoth, Cthulhu, ShubNiggurath, YogSothoth } public Transform[] symbolSlots; public GameObject[] eldritchSymbolPrefabs; public GameObject portal; public Animator portalAnimator; public AudioSource gatewayAudio; public AudioClip placeSymbolSound; private GameObject player; private AudioSource playerAudioSource;
private void Start() { player = GameObject.Find("Player"); playerAudioSource = player.GetComponent(); } private List correctOrder = new List() { EldritchSymbols.Nyarlathotep, EldritchSymbols.Azathoth, EldritchSymbols.Cthulhu, EldritchSymbols.ShubNiggurath, EldritchSymbols.YogSothoth };
private List currentOrder = new List();
private Dictionary<EldritchSymbols, int> symbolToSlotIndex = new Dictionary<EldritchSymbols, int>() { { EldritchSymbols.Nyarlathotep, 0 }, { EldritchSymbols.Cthulhu, 2 }, { EldritchSymbols.Azathoth, 1 }, { EldritchSymbols.ShubNiggurath, 3 }, { EldritchSymbols.YogSothoth, 4 } }; public void PlaceSymbol(EldritchSymbols symbol) { int slotIndex = symbolToSlotIndex[symbol]; if (symbolSlots[slotIndex].childCount == 0) { GameObject symbolObject = Instantiate( eldritchSymbolPrefabs[(int)symbol], symbolSlots[slotIndex].position, Quaternion.Euler(0, 24, -90), // Rotate 90 degrees around the Z axis symbolSlots[slotIndex]); if (!currentOrder.Contains(symbol)) // Check if the symbol is already in the list { currentOrder.Add(symbol); // Add it only if it's not present } playerAudioSource.PlayOneShot(placeSymbolSound); }
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.