i am having a issue with my code, i want to move the gameobject paddle with my mouse, it works partially. when the game starts , the paddle is on the right side of the screen and only moves half way across the screen. Camera Position is 0,0,0. but when i move the camera half way to the right side my paddle now moves across the whole play space. i cant do that because my bricks get dynamically created correctly when the camera is 0,0,0.
using UnityEngine;
using System.Collections;
public class Paddle : MonoBehaviour {
public float Speed = 1f;
float xmin;
float xmax;
float padding = 1f;
// Update is called once per frame
void Start(){
float distance = transform.position.z - Camera.main.transform.position.z;
Vector3 leftmost = Camera.main.ViewportToWorldPoint (new Vector3 (0, 0, distance));
Vector3 rightmost = Camera.main.ViewportToWorldPoint(new Vector3(1,0,distance));
xmin = leftmost.x + padding ;
xmax = rightmost.x - padding;
}
void Update () {
Movement ();
}
void Movement(){
Vector3 paddlePos = new Vector3 (this.transform.position.x, this.transform.position.y, 0f);
float MousePos = Input.mousePosition.x / Screen.width*16;
//restrict the player to the game space
paddlePos.x = Mathf.Clamp (MousePos, xmin, xmax);
this.transform.position = paddlePos;
}
}