I'm trying to make my player stop at the screen border in a 2D game, but I can't because I "Cannot modify the return value of "Component.transform" because it is not a variable. Code (CSharp): if (Input.GetKey("down")) { transform.position -= ymov * Time.deltaTime; DirectionDown(); if (transform.position.y < -4) { transform.position.y = -4; } } So I ended up trying to use a Vector3 to set the position, and it worked, except for the fact that the player moved to the center of the X-Axis because the Vector3 X value was set to 0. I tried putting in the transform.position.x as a value for the Vector3, but because it cannot reference a "Component.transform". Code (CSharp): public Vector3 vborder = new Vector3(transform.position.x, 4.5F, 0); What do I do?
I managed to make a solution. Since you couldn't add a non-static variable to a static variable, (or something like that), I just created the Vector3 variables in the Update method to make the variable non-static.
ive heard that this can cause issues later on in development, and is generally kinda "hackjob". but im not absolutely sure why to be honest (pretty new to this)