Hey there Unity,
I haven’t had much use for arrays, but this is one I figure it would be incredibly more efficient to do so. Currently I have no idea where to start other than to make a gameObject array. I could really use a point in the right direction.
Also, if someone could explain the different between a list and array that would be helpful.
I’m not asking for a rewrite/fix or anything, but if you’re feeling generous I tend to learn from example. Just comment it out somewhat so I know what’s happening.
Else, I would appreciate a link where I can find out how to make arrays like this, and what parameters I need to use to do so.
Thanks!
By the way, this code is for a GUI window with changing text, two buttons (forward and backwards) and one exit button in the top right.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class StartingGUI : MonoBehaviour {
//Audio
public AudioClip click;
//Bools
public bool showText1 = false;
public bool showText2 = false;
public bool showText3 = false;
//GameObjects
public GameObject Text1;
public GameObject Text2;
public GameObject Text3;
void Start(){
//Make our first window show
showText1 = true;
}
void Update(){
//If our first window bool is true
if (showText1) {
Text1.SetActive (true);
//Make the gameObject holding the text active.
} else {
//If the bool isn't true..
Text1.SetActive(false);
//Set as inactive, disabling the gameObject.
}
if (showText2) {
Text2.SetActive(true);
} else {
Text2.SetActive(false);
}
if (showText3) {
Text3.SetActive(true);
} else {
Text3.SetActive(false);
}
}
public void GoToRight (){
//If we click the arrow-to-the-right button..
transform.parent.audio.PlayOneShot (click,0.2f);
//if we're on the first page..
if (showText1) {
//Go to the second page and disable the first one.
showText2 = true;
showText1 = false;
}
if (showText2) {
showText3 = true;
showText2 = false;
}
}
public void GoToLeft (){
transform.parent.audio.PlayOneShot (click,0.2f);
if (showText2) {
showText2 = false;
showText1 = true;
}
}
public void Exit (bool showGUI){
//If we click the exit button, exit the window.
transform.parent.audio.PlayOneShot (click,0.2f);
transform.parent.GetComponent<Canvas> ().enabled = false;
}
}