CakeMeister

3d ball Player phan 4

Jul 20th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 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.     public int points = 0;
  12.     // Use this for initialization
  13.     void Start () {
  14.         rid = GetComponent<Rigidbody>();
  15.     }
  16.    
  17.    
  18.     void Update () {
  19.         float h = Input.GetAxis("Horizontal");
  20.         float v = Input.GetAxis("Vertical");
  21.  
  22.         direction.x = h;
  23.         direction.z = v;
  24.  
  25.         rid.AddForce(direction.normalized*speed*Time.deltaTime);
  26.     }
  27.  
  28.     private void OnTriggerEnter(Collider other)
  29.     {
  30.         if (other.CompareTag("cube"))
  31.         {
  32.             points += 1;
  33.             other.gameObject.SetActive(false);
  34.         }
  35.     }
  36.  
  37. }
Add Comment
Please, Sign In to add comment