Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Player : MonoBehaviour
- {
- public int score = 0;
- Rigidbody rb;
- public static float speed = 50f;
- Vector3 v, r;
- // Start is called before the first frame update
- void Start()
- {
- rb = GetComponent<Rigidbody>();
- }
- // Update is called once per frame
- void Update()
- {
- float x = 0, y = 0, z = 0, j = 0;
- if (Input.GetKey(KeyCode.W))
- {
- z = 1;
- }
- if (Input.GetKey(KeyCode.A))
- {
- y = -1;
- }
- if (Input.GetKey(KeyCode.S))
- {
- z = -1;
- }
- if (Input.GetKey(KeyCode.D))
- {
- y = 1;
- }
- if (Input.GetKey(KeyCode.Space))
- {
- if (transform.position.y <= 0.55)
- {
- j = 10;
- z += 1;
- }
- }
- Vector3 v = new Vector3(x, j, z)*speed;
- Vector3 r = new Vector3(0, y, 0)*200;
- rb.AddRelativeForce(v);
- rb.AddTorque(r);
- }
- private void FixedUpdate()
- {
- rb.AddRelativeForce(v);
- rb.AddRelativeTorque(r);
- }
- }
Add Comment
Please, Sign In to add comment