In the future, try to post the existing script to start with…
Anyway, here’s how to do this–
basically, when you create the object, you are storing its reference in some var, then use that to access its position… You can use GetMouseButtonDown,GetMouseButton, and GetMouseButtonUp to keep track of the current state of everything:
var objectToInstantiate : GameObject;
private var myCurrentObject : GameObject;
function Update(){
if(Input.GetMouseButtonDown(0)){
myCurrentObject = Instantiate(objectToInstantiate,Input.mousePosition,Quaternion.identity);
}
if(Input.GetMouseButton(0) && myCurrentObject){
myCurrentObject.transform.position = Input.mousePosition;
}
if(Input.GetMouseButtonUp(0) && myCurrentObject){
myCurrentObject = null;
}
}
this is a simple example of how this could work, hope this helps!
EDIT: sorry, just noticed the object is a textmesh… my above answer uses the input mouse position directly, which might work for say, a GUI element, which uses similar coordinates… however, for a normal gameobject, we would need to cast the mouse position to a world position:
var objectToInstantiate : GameObject;
private var myCurrentObject : GameObject;
function Update(){
if(Input.GetMouseButtonDown(0)){
myCurrentObject = Instantiate(objectToInstantiate, camera.ScreenToWorldPoint(Input.mousePosition),Quaternion.identity);
}
if(Input.GetMouseButton(0) && myCurrentObject){
myCurrentObject.transform.position = camera.ScreenToWorldPoint(Input.mousePosition);
}
if(Input.GetMouseButtonUp(0) && myCurrentObject){
myCurrentObject = null;
}
}
for example
(this script would be attached to your camera… )
also, you may need to adjust the z position in this scenario, which could be done directly after setting the rest, by adding the line:
myCurrentObject.transform.position.z = 10; // or whatever
immediately after setting the position in GetMouseButton, and also after the Instantiate line…
...
if(Input.GetMouseButton(0) && myCurrentObject){
myCurrentObject.transform.position = camera.ScreenToWorldPoint(Input.mousePosition);
myCurrentObject.transform.position.z = 10;
}
...