To make the Getkey function false right away when the player reach to a specific position.
I want my player to go up when I press the W key and I have set the Boundries for player to not go outside the boundries and same I did to go down but when I press one of the key w or s and when my player hit that boundry it stop moving on Z axis and it stuck there and when i released that button it start moving again I want that when I Keep press down the 'w' or 's' key and player hit the boundry it doesn't stop moving on Z axis. Thanks in advance Here is the code. void void MakeInstance() { if (instance == null) { instance = this; } } MoveUpDown(){
if (!up) { if (Input.GetKey(KeyCode.W)) { myBody.velocity = new Vector3(0f, speed * Time.deltaTime, 0f); } }
if (Input.GetKeyUp(KeyCode.W))
{
myBody.velocity = Vector3.zero;
}
if (!down)
{
if (Input.GetKey(KeyCode.S))
{
myBody.velocity = new Vector3(0f, -speed * Time.deltaTime, 0f);
}
}
if (Input.GetKeyUp(KeyCode.S))
{
myBody.velocity = Vector3.zero;
}
} The below is the script for playerboundries public class PlayerBounds : MonoBehaviour { private float minY = -0.57f, maxY = 0.22f;
private void Awake()
{
}
// Update is called once per frame
void Update()
{
Vector3 temp = transform.position;
if (temp.y > maxY)
{
temp.y = maxY;
LeftRightUpDownMove.instance.up = true;
LeftRightUpDownMove.instance.down =false;
}
if (temp.y < minY)
{
temp.y = minY;
LeftRightUpDownMove.instance.down = true;
LeftRightUpDownMove.instance.up = false;
}
transform.position = temp;
}
}
Your answer

Follow this Question
Related Questions
How can I have the video player in 5.6 ONLY play the video if a certain key is being held down? 0 Answers
GetKeyDown breaks jumping vs GetKey 1 Answer
Regularly rotation control with keys,Regularly Rotation control by keys 0 Answers
Unity Update is ignoring the GetKey part of my statement!? 2 Answers
GetAxis very smoothed or have a small delay when i press a key 0 Answers