vendredi 4 août 2017

How to randomize data in unity using JavaScript

I have a text file in project with some text data. Using below code I'm showing my data one line at a time when player click on a button (called NEXT).

For some reason what I want to do is make a button called "RANDOM". And when player will click on that a random line from the text file will be shown. Here is my JavaScript Code:

#pragma strict


import UnityEngine.UI;

var textFile : TextAsset;
var dialogLines : String [];
var lineNumber : int;

var uiText : Text;
var canvas : Canvas;


function Start () {
    if (textFile){
        dialogLines = (textFile.text.Split("\n"[0]));
}


}

function Update () {
    if(lineNumber <0){
    lineNumber = 0;
    }

    var dialog : String = dialogLines[lineNumber];
    uiText.text = dialog;
}

function Next () {
    lineNumber +=1;

}




Aucun commentaire:

Enregistrer un commentaire