Question by
kpage90 · Dec 03, 2020 at 05:33 PM ·
c#script.camera-movementplayer movement
How do I stop my players movement when I press a button and then enable it after I let the button go?
I have a script I am writing that is my Player Controller script. Inside the script I have...
public void CameraMovement()
{
turnSpeed += Input.GetAxis("Mouse X") * RotationSensitivity * Time.deltaTime;
PC_Character.transform.eulerAngles = new Vector3(0.0f, turnSpeed, 0.0f);
if (Input.GetMouseButtonDown(2))
{
mouseIsClicked = true;
PC_Character.transform.Translate(new Vector3(0,0,0));
}
if (Input.GetMouseButtonUp(2))
{
mouseIsClicked = false;
PC_Character.transform.eulerAngles = originPosition;
}
if (mouseIsClicked)
{
tiltSpeed += Input.GetAxis("Mouse Y") * RotationSensitivity * Time.deltaTime;
PC_Character.transform.eulerAngles = new Vector3(tiltSpeed, turnSpeed, 0.0f);
}
}
This lets me click the mouse roller ball and control the camera to look around.
I want that same button to disable the player movement. How can I do that? Here is how I have the player movement input.
public void PlayerMove()
{
if (Input.GetKey(KeyCode.W))
{
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.S))
{
transform.Translate(Vector3.back * speed * Time.deltaTime);
}
if (Input.GetMouseButtonDown(1))
{
speed = 16.0f;
}
if (Input.GetMouseButtonUp(1))
{
speed = 8.0f;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613021020im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How Do I Adjust Values Over A Gradual Amount of Time ? 4 Answers
Transfering script to other game objects via code (Unity 2D) 0 Answers
How do you move the camera with the player. Whats wrong with my code? 0 Answers
Error in camera script 1 Answer
How to have your player controls change while your camera rotates? 0 Answers