[Solved] Random generator lines stay and doesn't go away.

Hi,

I have encountered a problem.
While making the text randomly generated lines out in, but it does not go away after a new line come out and it overlap the lines. Like the picture I post.

I am trying not to use OnGUI because it change its position on different platform.

// So I make use of ConditionUI to use the TextMash. the problem here is that the message doesn’t disappear and the new message are being overlap so it looks like a mess.

if(showText = true)
{
MakeText(message,new Vector2(0,0.06f),30,Color.black);
}

or need to use MakeText(“”,newVector2(0,0.06f),30,Color.black); to put somewhere?
or any of your help. Thank you.
^//

So, I’m wondering if anybody can help me solve it by stopping the overlap and change by itself when generating?

Here is my script, in C#.

using UnityEngine;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using MadLevelManager;

public class RandomTipScript : ConditionUI
{
    //public GUISkin GameSkin;

    private bool showText = false, someRandomCondition = true;
    private float currentTime = 100.0f, executedTime = 10.0f, timeToWait = 100.0f;
    string[] messages;
    string message ;

    TextMesh _text = null;

    void Start()
    {
        messages = new string[]{"Online Scam:\nBe Wary of Cheap Deals\nthat seem too good to be true!",
                                "Online Scam:\nReview the seller's reputation\nbefore making any purchases!",
                                "Online Scam:\nDo Not Share Your Credit Card\ndetails on unsecured websites!",
                                "Merry Christmas",
                                "You are cool!"};
        message = messages [0];
    }
   
    void OnMouseDown()
    {
        executedTime = Time.time;

    }

    void Update()
    {

        currentTime = Time.time;
        if (someRandomCondition)
       
        {
            showText = true;
            Random rnd = new Random ();
       
            int i = Random.Range (0, messages.Length + 1);
       
            message = messages [i];
            timeToWait = 100.0f;

            if(showText = true)
            {
                MakeText(message,new Vector2(0,0.06f),30,Color.black);
            }

        }

        if (timeToWait > 0)
        {
            timeToWait --;
            someRandomCondition = false;
        }
        else
        {
            someRandomCondition = true;

        }

    }

}

“someRandomCondition” awesome, love it :smile:

what does “MakeText(…)” do? where are you using “_text” ?

Actually the _text is just nothing, just forgotten to take away.
TextMash have some link with MakeText(…) literally make the text appear in the particular place if you place it under ConditionUI in script and in Hierarchy is under a game object UI.

Well, I am looking for help to solve my problem in the script because it doesn’t work properly now so if wondering anybody can help.

Not related, but wouldnt this line “int i =Random.Range(0, messages.Length+1);” cause an index out of range error? Why do you do +1?

Since we dont know how the MakeText method works, it can be difficult for us to help.

It is alright now. I solve it. Thanks for the advise.

For posterity, you should explain what was wrong and how you solved it, so people doing searches for their own problem later can see this thread and maybe fix it themselves.