Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerMovement : MonoBehaviour
- {
- public float moveSpeed = 5.0f;
- float x, z;
- public bool canMove = false;
- public float jumpforce;
- void FixedUpdate()
- {
- if (canMove==true)
- {
- x = 0;
- z = 0;
- // check to see if the W or S key are being pressed.
- z = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;
- // check to see if the A or D key are being pressed.
- x = Input.GetAxis("Horizontal") * Time.deltaTime * (moveSpeed / 2);
- // Move the character
- transform.Translate(x, 0, z);
- if (Input.GetKeyDown("space"))
- {
- transform.Translate(Vector3.up * jumpforce * Time.deltaTime, Space.World);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement