CakeMeister

3D ball player phan 2

Jul 20th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.55 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Player : MonoBehaviour {
  6.  
  7.  
  8.     public Rigidbody rid;
  9.     public Vector3 direction;
  10.     public float speed = 100f;
  11.     // Use this for initialization
  12.     void Start () {
  13.         rid = GetComponent<Rigidbody>();
  14.     }
  15.    
  16.    
  17.     void Update () {
  18.         float h = Input.GetAxis("Horizontal");
  19.         float v = Input.GetAxis("Vertical");
  20.  
  21.         direction.x = h;
  22.         direction.z = v;
  23.  
  24.         rid.AddForce(direction.normalized*speed*Time.deltaTime);
  25.     }
  26.  
  27.  
  28. }
Add Comment
Please, Sign In to add comment