- Home /
Question by
Golden_Gamer · Feb 05, 2018 at 10:28 PM ·
c#movementgameobjecttransforminput
Code Not Working
I've tried a few different ways and looked at about 12 articles/tutorials but I can't find out what' wrong. public class MovingTapBox : MonoBehaviour {
Vector3 MousePos;
public int TapDamage = 10;
void MovingClickBox()
{
if (Input.GetMouseButtonDown(0) == true)
{
MousePos = Input.mousePosition;
gameObject.transform.position = MousePos;
}
}
I'm trying to make the game object move according to the position of the mouse when they click.
Comment
Best Answer
Answer by Buckslice · Feb 05, 2018 at 11:38 PM
Well your MovingClickBox() function looks fine but it is probably not getting called since you have no Update() function. The Unity tutorials are a great way to learn the basics of the engine where they explain this in more depth.
Also saying "code not working" could mean a lot of things... Please eleborate, like are there errors? does it compile? does it do something different than you expect? does it do nothing at all?