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 P1Script : MonoBehaviour
- {
- public Rigidbody rb;
- public float speed = 2.5f;
- private bool left = false;
- private bool right = false;
- private bool down = false;
- private bool up = false;
- private float velH = 0.0f;
- private float velV = 0.0f;
- // Start is called before the first frame update
- void Start()
- {
- rb = GetComponent<Rigidbody>();
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKey(KeyCode.A))
- {
- left = true;
- }
- if (Input.GetKeyUp(KeyCode.A))
- {
- left = false;
- }
- if (Input.GetKey(KeyCode.D))
- {
- right = true;
- }
- if (Input.GetKeyUp(KeyCode.D))
- {
- right = false;
- }
- velH = 0;
- if ( left )
- {
- velH++;
- }
- if (right)
- {
- velH--;
- }
- if (Input.GetKey(KeyCode.W))
- {
- up = true;
- }
- if (Input.GetKeyUp(KeyCode.W))
- {
- up = false;
- }
- if (Input.GetKey(KeyCode.S))
- {
- down = true;
- }
- if (Input.GetKeyUp(KeyCode.S))
- {
- down = false;
- }
- velV = 0;
- if (up)
- {
- velV++;
- }
- if (down)
- {
- velV--;
- }
- rb.velocity = (new Vector3(velV, 0, velH) * speed);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement