Hi! i need a little help in the OnUserInpt function

using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;

public class Hacker : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
MenuInicial();

}



void MenuInicial()
	{
	Terminal.WriteLine("Qual o seu nome?");
	

	}
void OnUserInput(string input)
{

	Menuprincipal(input);
}




void Menuprincipal(string Nome)
{
	Terminal.ClearScreen();
	var Inicio = "ola " + Nome;
	Terminal.WriteLine(Inicio);
	Terminal.WriteLine("Bem vindo ao terminal"); 
	Terminal.WriteLine("Aperte 1 para o Pc da casa");
	Terminal.WriteLine("Aperte 2 para o Pc da Vizinha");
}





// Update is called once per frame
void Update()
{
	
}

}

This is my code, i did it so when starting the Terminal , first i would ask the name, so when starting, the name chosen by the player would stay in the begging , but i dont want it to happens every time the player write something , but just that one time in the first screen, how can i make it happens just one time?

Hi Oziel,

Rick had the same idea as you, and he is going to show you how to achieve that in the following lectures. Please keep watching. :slight_smile:


See also:

1 Like

I did it! Thx , saw the other lectures and try to use the ideia in the screen selection.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Hecker2 : MonoBehaviour
{

string ID;
int level;
enum Tela {Menuinicial, MenuPrincipal, MenuDeJogo, Vitoria};
Tela TelaAtual;

// Start is called before the first frame update
void Start()
{
    MenuInicial();

}



void MenuInicial()
{

	TelaAtual = Tela.Menuinicial;
	Terminal.WriteLine("Qual o seu nome?");
	
}

void Menuprincipal(string ID)
{
	TelaAtual = Tela.MenuPrincipal;
	Terminal.ClearScreen();
	var Inicio = "ola " + ID;
	Terminal.WriteLine(Inicio);
	Terminal.WriteLine("Bem vindo ao terminal"); 
	Terminal.WriteLine("Aperte 1 para o Pc da casa");
	Terminal.WriteLine("Aperte 2 para o Pc da Vizinha");
}

void OnUserInput(string input)
	{	
		if (TelaAtual == Tela.Menuinicial)
		{
			ID = input;
			Menuprincipal(ID);
		}
		else if (input == "menu")
		{
			Menuprincipal(ID);
		}
		else if (TelaAtual == Tela.MenuPrincipal)
		{
			if (input == "1")
			{
			level = 1;
			StartGame();
			}
			else if (input == "2")
			{
			level = 2;
			StartGame();
			}
		
			else
			{
			Terminal.WriteLine("Escolha uma opçao valida");
			}
		}
		
	
	}

	void StartGame()
{
	TelaAtual = Tela.MenuDeJogo;
	Terminal.WriteLine("Voce escolheu a opçao" + level);
}

// Update is called once per frame
void Update()
{
    
}

}

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms