Hi Pro, Thx so much. Since I donnot wanna display all comments at one touch so I use random to generate random number. Now I hv sucessfully saved my data. But how can display it on screen?
I wanna dynamically create a 3D text to display those pre-saved text, and place the 3D text in the position where last touch ends. How can do it?
thx in advance. BTW this is last thing I have to do. thx so much!
Here is my script, Anyone please help me with the last thing! I really want it to be done ASAP!!
void Update () {
Plane targetPlane = new Plane(transform.up, transform.position);
//message.text = "";
foreach (Touch touch in Input.touches) {
//Gets the ray at position where the screen is touched
Ray ray = Camera.main.ScreenPointToRay(touch.position);
//Gets the position of ray along plane
float dist = 0.0f;
//Intersects ray with the plane. Sets dist to distance along the ray where intersects
targetPlane.Raycast(ray, out dist);
//Returns point dist along the ray.
Vector3 planePoint = ray.GetPoint(dist);
//Debug.Log("Point=" + planePoint);
//True if finger touch began. If ray intersects collider, set pickedObject to transform of collider object
if (touch.phase == TouchPhase.Began) {
//Struct used to get info back from a raycast
RaycastHit hit = new RaycastHit();
if (Physics.Raycast(ray, out hit, 1000)) { //True when Ray intersects colider. If true, hit contains additional info about where collider was hit
pickedObject = hit.transform;
lastPlanePoint = planePoint;
} else {
pickedObject = null;
}
//Move Object when finger moves after object selected.
} else if (touch.phase == TouchPhase.Moved) {
if (pickedObject != null) {
pickedObject.position += planePoint - lastPlanePoint;
lastPlanePoint = planePoint;
}
//Set pickedObject to null after touch ends.
} else if (touch.phase == TouchPhase.Ended) {
//myText = GetComponent(TextMesh);
// myText.text = PlayerPrefs.GetString(name); // how can I display all comments each time one by one?
// myText.transform.position = pickedObject.transform.position;
Debug.Log(PlayerPrefs.GetString(count+n));
GUI.Label(new Rect(50,30,350,30),PlayerPrefs.GetString(count+Random.Range(n)));
pickedObject = null;
}
}
}
void OnGUI() {
//if(targetsFound){
GUI.Window(0,new Rect((Screen.width/2)-100,(Screen.height/2)-100,500,500),Comt,"Type your comments");
//}
}
void Comt(int id){
// set the text field for user to type their comments
comments=GUI.TextArea(new Rect(20,80,450,200),comments);
GUI.Label(new Rect(50,70,350,30),"Drag to see others' comments");
//GUI.Label(new Rect (20, 300, 60, 30), "Nickname");
//name= GUI.TextField (new Rect(80,300,100,80),name);
if (GUI.Button(new Rect(240,320,80,30),"OK")){
PlayerPrefs.SetString(count+n,comments); // save the comment to playerprefs
//Debug.LogWarning(PlayerPrefs.GetString(name));
comments= "";
//name= "";
n++;
}
}
Hi there,
i hv fixed. Hhaha. I am so stupid!! just create a new 3Dtext with empty string and attach just one script to parent object : GetComponentInChildren(TextMesh).text = ""+timer;
thats done!! :)