- Home /
Change GUI text on mouse up Java script
Hi I need help with changing a gui text.
I have 4 box collides for my ship selection screen, and when the player selects one of the boxes to pick their ship I would like a gui text to say which ship was last selected and I'd like it so the text changes if the player picks a different ship.
It would be similar to how the debug code looks but im unsure how to apply it to a gui text here's my code so far
//this is the currently selected Player. Also the one that will be saved to PlayerPrefs var selectedPlayer : int = 0;
function Update()
{
if (Input.GetMouseButtonUp (0)) {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 100))
{
// The pink text is where you would put the name of the object you want to click on (has attached collider).
if(hit.collider.name == "ShipBox1")
SelectedCharacter1(); //Sends this click down to a function called "SelectedCharacter1(). Which is where all of our stuff happens.
if(hit.collider.name == "ShipBox2")
SelectedCharacter2();
if(hit.collider.name == "ShipBox3")
SelectedCharacter3();
//if(hit.collider.name == "ShipBox4")
//SelectedCharacter4();
}
else
{
return;
}
}
}
function SelectedCharacter1() {
Debug.Log ("Character 1 SELECTED"); //Print out in the Unity console which character was selected.
selectedPlayer = 1;
PlayerPrefs.SetInt("selectedPlayer", (selectedPlayer));
}
function SelectedCharacter2() {
Debug.Log ("Character 2 SELECTED");
selectedPlayer = 2;
PlayerPrefs.SetInt("selectedPlayer", (selectedPlayer));
}
function SelectedCharacter3() {
Debug.Log ("Character 3 SELECTED");
selectedPlayer = 3;
PlayerPrefs.SetInt("selectedPlayer", (selectedPlayer));
//}
//function SelectedCharacter4() {
//Debug.Log ("Character 4 SELECTED");
//selectedPlayer = 4;
//PlayerPrefs.SetInt("selectedPlayer", (selectedPlayer));
}
Comment
Your answer