- Home /
Question by
BusterBlader · Mar 27, 2015 at 03:01 PM ·
2dobjectmoveclick
move UI object to click position
Hello Guys,
I'm working on a small game and everything consists of UI objects so I don't have a camera in the scene. Now I want to move an object to a click position on the screen. I've seen many examples but they mostly use Camera.main.ScreenToWorldPoint(); which doesn't work without a camera. Is there another way or another function I could use? Thanks in advance.
Comment
Answer by maccabbe · Mar 27, 2015 at 03:07 PM
You could probably use Input.mousePosition without any processing, i.e. the following makes the center of a new text object follow the mouse cursor
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
void Update () {
transform.position=new Vector3(Input.mousePosition.x, Input.mousePosition.y, transform.position.z);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613191326im_/https://answers.unity.com/themes/thub/images/avi.jpg)