- Home /
Help with arrays of gameobjects
I'm new to coding and I'm trying to "learn by doing" doing a small point and click game. I've set up a trigger around a character that will activate a speech bubble with an icon in it, on clicking the icon the player will get a small bit of dialogue that's a hint of what to look for next. I've set up an array of these icons that I'd like to swap out. I'm using a check if a particular item is in their inventory to then say if they have that item, then display this particular object from the array. The problem is that now that I've added a new one it only displays that, it's not setting active what i need it to. Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hints : MonoBehaviour
{
public GameObject SpeechBubble;
public GameObject UI_Box;
public GameObject UI_Transparency;
public GameObject UI_UncoatedScreen;
public GameObject Inventory;
public GameObject[] HintIcons;
void OnTriggerEnter(Collider collider)
{
SpeechBubble.SetActive(true);
HintIcons[0].SetActive(true);
if(Inventory.activeSelf)
{
HintIcons[0].SetActive(false);
HintIcons[1].SetActive(true);
HintIcons[2].SetActive(false);
HintIcons[3].SetActive(false);
}
else if (UI_Transparency.activeSelf)
{
HintIcons[0].SetActive(false);
HintIcons[1].SetActive(false);
HintIcons[2].SetActive(true);
HintIcons[3].SetActive(false);
}
else if (UI_UncoatedScreen.activeSelf);
{
HintIcons[0].SetActive(false);
HintIcons[1].SetActive(false);
HintIcons[2].SetActive(false);
HintIcons[3].SetActive(true);
}
}
void OnTriggerExit (Collider collider)
{
SpeechBubble.SetActive(false);
}
}
Now anytime entering it's always setting active HintIcon[3] even though the UI element I'm asking for it to look for is inactive. I'm not sure what to do. Also if this is just a very dumb way to go about setting this up I'll take any guidance on a better one.
Thanks!
Your answer
Follow this Question
Related Questions
How would I use and make an array of triggers? 2 Answers
Detecting multiple gameobjects 1 Answer
Problem with 2+ of the same scripts on the same object and functions 1 Answer
Using arrays with OnTriggerEnter 0 Answers
Need help with setting all items of a specific tag to "inactive" when i die. 1 Answer