[Noob] Do you need to know Pixels per Unit and game blocks / how to code without referencing game blocks?
I'm trying to learn Unity through the Udemy lessons, and I'm doing the lessons on how to make a Block Breaker game. Throughout the tutorial once in awhile the teacher changes the pixels per unit and references something about the game blocks size. For most of the tutorial I haven't been following that part of the guide because I wanted to make my game bigger than 800x600 and I'm using my own sprites and things, so the calculations he does for Pixels per Unit and how many game blocks there is, is different from what mine would be, and I'd like to avoid that part of Unity for now if I can.
I didn't run into any problems until we started coding the behaviour of the paddle (just a rectangle with a static y position that moves along the x axis sticking to the mouse). He codes the behaviour based on the mouse position in blocks, but I don't know how many blocks my game is. Is there a way to code this behaviour without referencing blocks?
This is my code right now;
Vector3 paddlePos = new Vector3 (0f, this.transform.position.y, 0f);
//what the tutorial shows: float mousePosInBlocks = Input.mousePosition.x / Screen.width * 16;
//instead of float mousePosInBlocks, I need it to work off of where the mouse is relative to the screen size... or something.
float mousePos = Input.mousePosition.x;
paddlePos.x = mousePos;
this.transform.position = paddlePos;
}
Right now, my paddle does move left or right when I move the mouse, but it doesn't stick to the mouse. It moves left or right relative to where my mouse was when the game started. Is it possible to do this without referencing Game blocks? If no, then how do I know how many game blocks I have? I'm working off fixed resolution 1280x800 right now, with the camera centred at 0,0. the left and right edges of the camera are at -83.7and 83.82, respectively.