Object following mouse problem PLZ help
using UnityEngine; using System.Collections;
public class Bouncer : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector3 PaddlePos = new Vector3 (0.5f, this.transform.position.y, 0f);
float mousePosInBlocks = (Input.mousePosition.x / Screen.width * 16);
PaddlePos.x = mousePosInBlocks;
if (PaddlePos.x > 15.5f) {
PaddlePos.x = 15.5f;
}
if (PaddlePos.x < 0.5f) {
PaddlePos.x = 0.5f;
}
this.transform.position = PaddlePos;
}
}
This is my code im trying to make a old block breaker game, with the paddle following the mouse. I'm trying to limit how far the paddle can go on the X axis. Works perfectly on the right side/15.5f but for the left side it goes through the side through the other end than stops halfway. I'm really confused :P any help would be appreciative
Thank you so much haha. I was watching another tutorial but he was on unity 4.6 and it didnt work on unity 5 i think it was that he wasn't using get axis! But seriously thank you!
Your answer
Follow this Question
Related Questions
Bullet to Mouse Position? 1 Answer
Getting mouseposition outside of Editor Window in Scene View 1 Answer
Can't get a gameObject to follow my mouse 0 Answers
Raycast not drawing where i tell it 1 Answer
Shoot towards mouse with offset 0 Answers