Advertisement
AL4ST4I2

ballcontrol

Sep 22nd, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class BallControll : MonoBehaviour {
  5.  
  6.     public float highJump = 10.0F;
  7.     public float speed = 10.0F;
  8.     private Rigidbody rb;
  9.  
  10.     private float x = 0.0f;
  11.     private float y = 0.0f;
  12.     private float z = 0.0f;
  13.  
  14.     void Start()
  15.     {
  16.         rb = GetComponent<Rigidbody>();
  17.     }
  18.    
  19.     // Update is called once per frame
  20.     void FixedUpdate () {
  21.         getMovement();
  22.        
  23.     }
  24.  
  25.     void getMovement()
  26.     {        
  27.         if (Input.GetKey(KeyCode.D))
  28.         {
  29.             x = 1.0f; y = 0.0f; z = 0.0f;
  30.         }
  31.         else if (Input.GetKey(KeyCode.A))
  32.         {
  33.             x = -1.0f; y = 0.0f; z = 0.0f;
  34.         }
  35.         else if (Input.GetKey(KeyCode.W))
  36.         {
  37.             z = 1.0f; y = 0.0f; x = 0.0f;
  38.         }
  39.         else if (Input.GetKey(KeyCode.S))
  40.         {
  41.             z = -1.0f; y = 0.0f; x = 0.0f;
  42.         }
  43.         else if (Input.GetKey(KeyCode.Space))
  44.         {
  45.             y = 1.0f; y = 0.0f; z = 0.0f;
  46.         }
  47.         else if (Input.GetKey(KeyCode.C))
  48.         {
  49.             x = -x; y = -y; z = -z;
  50.         }
  51.         else
  52.         {
  53.             x = 0.0f;
  54.             y = 0.0f;
  55.             z = 0.0f;
  56.             myMuovi(new Vector3(x, y, z));
  57.         }
  58.  
  59.         myMuovi(new Vector3(x, y, z)) ;
  60.        
  61.     }
  62.  
  63.  
  64.  
  65.     void myMuovi(Vector3 inpu)
  66.     {
  67.        
  68.         rb.AddForce(inpu * speed);
  69.        
  70.     }
  71.  
  72.  
  73.     void muovi()
  74.     {
  75.         float moveX = Input.GetAxis("Horizontal") ;
  76.         float moveZ = Input.GetAxis("Vertical") ;
  77.  
  78.         Vector3 movement = new Vector3(moveX, 0.0F, moveZ);
  79.         rb.AddForce(movement * speed);
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement