Copying and Pasting cs Code
In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.
For example, you can follow the pattern in this listing: void MovementControls()
{
float screenSpeed = 0;
float horizontalInput = 0;
float verticalInput = 0;
screenSpeed = CameraMotor.speedScreen;
//moving right
if (Input.GetKey(KeyCode.D))
horizontalInput = speedCurrent;
//moving left
if (Input.GetKey(KeyCode.A))
horizontalInput = -speedCurrent;
//moving up
if (Input.GetKey(KeyCode.W))
verticalInput = speedCurrent;
//moving down
if (Input.GetKey(KeyCode.S))
verticalInput = -speedCurrent;
//result velocity
rb.velocity = new Vector3(horizontalInput, 0, screenSpeed + verticalInput);
}
{
float screenSpeed = 0;
float horizontalInput = 0;
float verticalInput = 0;
screenSpeed = CameraMotor.speedScreen;
//moving right
if (Input.GetKey(KeyCode.D))
horizontalInput = speedCurrent;
//moving left
if (Input.GetKey(KeyCode.A))
horizontalInput = -speedCurrent;
//moving up
if (Input.GetKey(KeyCode.W))
verticalInput = speedCurrent;
//moving down
if (Input.GetKey(KeyCode.S))
verticalInput = -speedCurrent;
//result velocity
rb.velocity = new Vector3(horizontalInput, 0, screenSpeed + verticalInput);
}