- Home /
Question by
abhishakverma · May 31, 2014 at 06:06 AM ·
c#
How can I Store the data and display on game window?
Here i am going to paste my code please check it. It's working fine but i need a suggestion from your side for any modification. Thanks guys. using UnityEngine; using System.Collections; using System.Collections.Generic; using System;
public class playeclass: MonoBehaviour {
public string PlayerNAME = "";
public string SavedNAME;
public static string movename;
int counter =0;
int[] numbers = new int[] {0, 1, 2,};
public Material material1;
public Material material2;
public Material material3;
bool FirstMaterial = false;
bool SecondndMaterial = false;
bool ThirdMaterial =false;
void Start () {
SavedNAME = PlayerPrefs.GetString("Stored Name",PlayerNAME);
if(SavedNAME != null)
{
print(SavedNAME);
PlayerNAME = SavedNAME; // show the current SavedNAME in the GUI.TextArea
}
renderer.material = material1;
}
// Update is called once per frame
void Update () {
}
void OnMouseDown(){
Debug.Log("a"+main_class.a);
if(counter>numbers.Length-1){
counter=0;
}
if(numbers[counter] ==0){
//Debug.Log("color2");
renderer.material = material2;
SecondndMaterial = true;
FirstMaterial = false;
ThirdMaterial=false;
counter = counter +1;
main_class.a =1;
}
else if(numbers[counter] ==1){
//Debug.Log("color3");
renderer.material = material3;
ThirdMaterial = true;
FirstMaterial=false;
SecondndMaterial=false;
counter = counter +1;
main_class.a =2;
}
else if(numbers[counter] ==2){
Debug.Log("color1");
renderer.material = material1;
FirstMaterial = true;
SecondndMaterial = false;
ThirdMaterial=false;
counter = counter +1;
main_class.a =3;
}
}
void OnGUI()
{
GUI.Label(new Rect (10,30,100,25),"name");
PlayerNAME = GUI.TextArea (new Rect (65,30,100,25),PlayerNAME,10);
if(GUI.Button(new Rect(65,60,70,30),"submit"))
{
SavedNAME =(PlayerPrefs.GetString("Stored Name kkkkkk",PlayerNAME));
//SavedNAME(PlayerNAME);
movename = SavedNAME;
}
// GUI.Box(new Rect((Screen.width/2)-100, 10, 300, 50), "Hello " + SavedNAME);
}
/*void SaveName(String PlayerNAME)
{
PlayerPrefs.SetString("Stored Name", PlayerNAME);
SavedNAME = PlayerNAME; // reset SavedNAME to the PlayerNAME from GUI.TextArea and GUI.Button
}
*/
}
Comment
If it works fine and you see no problem then why request for our opinions?