Question by
adolphina13 · Mar 17, 2018 at 11:17 AM ·
physicstransformpositionprogrammingonmousedrag
OnMouseDrag doesn't wokr.
Hi. I am new to Unity trying to create my first game. I want my Player moving left and right, but not up and down (it is 2d game) I created Move Script and wrote, as in tutorial:
using UnityEngine;
public class Move : MonoBehaviour {
public Transform Player;
void OnMouseDrag()
{
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Player.position = new Vector2(mousePos.x, Player.position.y);
}
}
I connected script to player, but when i launch it doesn't work at all. Please help me and tech how to do it correct. The script is quiet simple, what is wrong? Thank a lot.
Comment
Your answer
Follow this Question
Related Questions
gameobject position lerp 0 Answers
Raycast only occurs on start 2 Answers
Terrain height -> loosing Players GO childs 0 Answers
How To Make An Object Appear In Front Of Player Without Cloning? 1 Answer