|
I wanted a simple system to display two lines of text,and every time i press the space bar,change the two lines to the next ones in a array,i assigned 6 lines in the inpector,but after i press the key for the second time,it load the next scene,without all the lines showing.
using UnityEngine;
using System.Collections;
public class sistemaconversa : MonoBehaviour {
public string [] texto1;
public string [] texto2;
public GUIText tex1;
public GUIText tex2;
int i = 0;
int o = 0;
void Start () {
i = texto1.Length;
tex1.text = texto1 [0];
tex2.text = texto2 [0];
}
// Update is called once per frame
void Update () {
if(Input.GetKeyUp("space"))
{
o +=1;
tex1.text = texto1 [+1];
tex2.text = texto2 [+1];
}
if(o > i )
{
Application.LoadLevel(Application.loadedLevel+1);
}
}
}
(comments are locked)
|
|
I do see one thing: Instead of It worked,didn't know variables can be use to call array elements.
May 12 '12 at 01:58 AM
MetalLord
You can use any expression to index an array.
May 12 '12 at 02:18 AM
aldonaletto
(comments are locked)
|
|
You're always showing the same messages (texto1[1] and texto2[1]). You should use the index o, and pass to LoadLevel when o gets == i (arrays range from 0 to Length-1):
...
if(Input.GetKeyUp("space")){
tex1.text = texto1 [o]; // display the messages index o...
tex2.text = texto2 [o];
o += 1; // then increment the index
}
if ( o >= i ){ // when o >= length, load level:
Application.LoadLevel(Application.loadedLevel+1);
}
...
(comments are locked)
|

Set o and i as public, then observe how they behave in the inspector during runtime. There is probably something going here.