PlayerMovement
How do I use Player Movement
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
35 | PlayerMovement (); | 1 |
43 | void PlayerMovement(){ | 2 |
11 |
movePlayer = GameObject.Find ("Player").GetComponent |
3 |
File name: PlayerController.cs
Copy
31 void Update () {
32 if (GameplayController.instance.gameInProgress) {
33 LimitPosition ();
34 if (Application.platform == RuntimePlatform.WindowsEditor) {
35 PlayerMovement ();
36 }else if(Application.platform == RuntimePlatform.Android){
37 TouchMovement ();
38 }
39
40 }
41 }
File name: PlayerController.cs
Copy
43 void PlayerMovement(){
44 if(Input.GetKey(KeyCode.LeftArrow)){
45 position.x -= speed * Time.deltaTime;
46 }else if(Input.GetKey(KeyCode.RightArrow)){
47 position.x += speed * Time.deltaTime;
48 }
49
50 position.x = Mathf.Clamp (position.x, maxLeft + 0.5f, maxRight - 0.5f);
51 transform.position = position;
52
53 }
File name: Movement.cs
Copy
10 void Start () {
11 movePlayer = GameObject.Find ("Player").GetComponent
12 }
Download file with original file name:PlayerMovement
PlayerMovement 119 lượt xem
Gõ tìm kiếm nhanh...