I need to create a GUIText everytime a player makes a correct move. Once the GUIText is created I need to move it to the top of the screen (Some what like bubbles). I have been able to create and move the GUIText. But whenever a new GUIText is created the previous ones stop updating and the GUIText doesnt move. I have been struggling to get it working for the past couple of days.
I am calling the initGuiText() inside OnCollisionEnter2d of another gameobject’s script.
Here is a screenshot of how it appears.
Is there a better way to implement what I am trying to achieve?
Here is my code :
#pragma strict
public class invokePlusOne extends MonoBehaviour{
var guiTextPrefab : GameObject;
var newGui : GameObject;
function initGuiText(colObj : Color32, pos :Vector3){
newGui = GameObject.Instantiate(guiTextPrefab,Vector3(0,0,0),Quaternion.identity);
newGui.name="guiText"+i;
newGui.guiText.text = "+1";
newGui.guiText.color=colObj;
newGui.guiText.fontSize=Screen.height/20;
//I do this to create GUIText at 4 different positions.
if(pos.x > 0){newGui.guiText.transform.position = Vector3(0.85,0.5,0.0); }
if(pos.x < 0){newGui.guiText.transform.position = Vector3(0.15,0.5,0.0); }
if(pos.y > 0){newGui.guiText.transform.position = Vector3(0.5,0.75,0.0); }
if(pos.y < 0){newGui.guiText.transform.position = Vector3(0.5,0.25,0.0); }
}
function Update(){
if(newGui!=null){
moveUp();
}
}
function moveUp(){
while(newGui.guiText.pixelOffset.y < 1000){
newGui.guiText.pixelOffset.y += 0.5*(Time.deltaTime);
yield;
}
}
}
Thanks in advance.