Guest User

Untitled

a guest
Apr 20th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TranslateScript : MonoBehaviour {
  6.  
  7.     float maxjump = 2 , power = 300, distGround;
  8.     Rigidbody myRigidbody;
  9.     // Use this for initialization
  10.     void Start () {
  11.        
  12.         myRigidbody = GetComponent<Rigidbody>();
  13.         distGround = GetComponent<BoxCollider>().bounds.extents.y;
  14.     }
  15.    
  16.     // Update is called once per frame
  17.     void Update () {
  18.        
  19.         if(Input.GetKey(KeyCode.UpArrow)){
  20.             transform.Translate(Vector3.forward * Time.deltaTime);
  21.         }
  22.        
  23.         if(Input.GetKey(KeyCode.DownArrow)){
  24.             transform.Translate(Vector3.back * Time.deltaTime);
  25.         }
  26.        
  27.         if(Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.RightArrow)){
  28.             transform.Translate(Vector3.right * Time.deltaTime);
  29.         }
  30.        
  31.         else if(Input.GetKey(KeyCode.RightArrow)){
  32.             transform.Rotate(0,1,0);
  33.         }
  34.        
  35.         if(Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.LeftArrow)){
  36.             transform.Translate(Vector3.left * Time.deltaTime);
  37.        
  38.         }
  39.        
  40.         else if(Input.GetKey(KeyCode.LeftArrow)){
  41.             transform.Rotate(0,-1,0);
  42.         }
  43.         if(isGrounded() && Input.GetKeyUp(KeyCode.Space)){
  44.             myRigidbody.AddForce(transform.up * power);
  45.         }
  46.     }
  47.     bool isGrounded(){
  48.         return Physics.Raycast(transform.position, -Vector3.up, distGround + 0.1f);
  49.  
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment