- Home /
How to make a "Click to Continue" text message?
I'm attempting to make a simple thing where you complete the requirements of an if statement, and text (UI) appears on screen, then you click to go to the next box and so forth. My problem stems from the fact that I don't know where to begin to look. I've tried color.lerp, and most of the tutorial videos I've scene don't work with my Unity (5.0.0). So if anyone has an Idea how to do this (Which I'm aware is rather simple I'm just stupid) I'd really appreciate to be pointed in the right direction.
Answer by Tanoshimi2000 · Apr 26, 2015 at 09:11 PM
This ought to do it for you. This will cycle through a list of messages you create in the Editor. I've tested the code and it works. You can add things to make it prettier, format the text, or position the box, but I'll leave that up to you.
using UnityEngine;
using System.Collections;
public class TextOnDemand : MonoBehaviour {
public string[] Messages; // Fill them in in the Editor, or you can figure how to load them
[HideInInspector]
public int CurrentMessageIndex = 0; // Default to first
public bool ShowMessages = true;
// Use this for initialization
void Start () {
// Load messages, if you did not make them in the Editor
}
// Update is called once per frame
void Update () {
// Handle Moving to next message on mouse click
if (Input.GetMouseButtonUp(0)) // Left Mouse Click to move forward
CurrentMessageIndex++;
if (Input.GetMouseButtonUp(1)) // Right Mouse Click to move backward
CurrentMessageIndex++;
// Turn off messages if we get t othe last one.
if (CurrentMessageIndex > Messages.GetUpperBound(0))
ShowMessages = false;
// Bounds checking
CurrentMessageIndex = Mathf.Clamp(CurrentMessageIndex, Messages.GetLowerBound(0), Messages.GetUpperBound(0));
}
void OnGUI()
{
// Now show the text
if (ShowMessages)
GUI.TextArea(new Rect(10, 10, 500, 200), Messages[CurrentMessageIndex]);
}
}