- Home /
Moving an object to a specific location
Hi Everyone, I'm a new developer here and I'm pulling my hair out. I'm trying to do something very simple, but it's not working and I can't figure out why! I'm trying to simply move an object from one location to another during runtime. Below is a sample of my code where I want to move the object "target" to location 0,0,0 when a touch occurs. Does anyone know what I'm doing wrong?
Thanks!
 public class BackgroundTouch : MonoBehaviour {
 
 public GameObject target; 
 
 // Use this for initialization
 void Start () {
     target = GameObject.Find("Target");
 }
 
 // Update is called once per frame
 void Update () {
     if (iPhoneInput.touchCount==0)
     {
         return;
     }
     
     target.transform.position = new Vector3(0,0,0);
     
 }
}
Answer by Bunny83 · Apr 04, 2012 at 06:08 PM
I don't see any problem with this as long as there's an object called "Target" and you're on an iPhone.
Anyway a early-exit in Update isn't really a good idea. Usually you have multiple things happening in Update.
It would be a bit more logical this way:
 if (iPhoneInput.touchCount>0)
 {
     target.transform.position = new Vector3(0,0,0);
 }
However your script should work as well.
Hey Thanks for the response Bunny! I actually wasn't even getting to the piece of code where it was changing the position...complete brain lapse! Also, thanks for the re$$anonymous$$der on proper coding procedures. It's been about 6 years since I've developed anything, but it's a quick ramp up! :)
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                