Question by
Brandoboy · Apr 24, 2017 at 08:31 PM ·
c#2dmousemouseposition
Can't get a gameObject to follow my mouse
okay so I have a abject (called 'Paddle') that I want to always follow my mouse, but only on the x coordinate. So far ive tried multiple things and none of them work. The paddle will follow my mouse, but its all messed up because it only starts following my mouse after a certain distance.
Here is my code: using UnityEngine; using System.Collections;
public class Paddle : MonoBehaviour {
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
print(Screen.width + "Screen Width");
print(Input.mousePosition.x + "Mouse Pos");
Vector3 paddlePos = new Vector3(0f, this.transform.position.y, 0f);
float mousePosInBlocks = Input.mousePosition.x / Screen.width * 41;
paddlePos.x = Mathf.Clamp(mousePosInBlocks, -9.5f, 9.5f);
this.transform.position = paddlePos;
}
}
Comment