Last active
September 7, 2021 02:08
-
-
Save curious-username/1db039c9aad1f48121ea5aa10bd28fd9 to your computer and use it in GitHub Desktop.
moving all player movement into a single method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Update() | |
{ | |
PlayerMovement(); | |
} | |
void PlayerMovement() | |
{ | |
float horizontalInput = Input.GetAxis("Horizontal"); | |
float verticalInput = Input.GetAxis("Vertical"); | |
transform.Translate(Vector3.right * horizontalInput * _speed * Time.deltaTime); | |
transform.Translate(Vector3.up * verticalInput * _speed * Time.deltaTime); | |
if (transform.position.y >= 5.7f) | |
{ | |
transform.position = new Vector3(transform.position.x, 5.7f, 0); | |
} | |
else if (transform.position.y <= -5.7f) | |
{ | |
transform.position = new Vector3(transform.position.x, -5.7f, 0); | |
} | |
if (transform.position.x >= 11.35f) | |
{ | |
transform.position = new Vector3(-11.35f, transform.position.y, 0); | |
} | |
else if (transform.position.x <= -11.35f) | |
{ | |
transform.position = new Vector3(11.35f, transform.position.y, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment