Advertisement
CakeMeister

3d Ball player phan 5

Jul 20th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Player : MonoBehaviour {
  7.  
  8.  
  9.     public Rigidbody rid;
  10.     public Vector3 direction;
  11.     public float speed = 100f;
  12.     public int points = 0;
  13.  
  14.     public Text wintext;
  15.     public Text scoretext;
  16.  
  17.     // Use this for initialization
  18.     void Start () {
  19.         rid = GetComponent<Rigidbody>();
  20.         scoretext.text = "Score: " + points.ToString();
  21.         wintext.text = "";
  22.     }
  23.    
  24.    
  25.     void Update () {
  26.         float h = Input.GetAxis("Horizontal");
  27.         float v = Input.GetAxis("Vertical");
  28.  
  29.         direction.x = h;
  30.         direction.z = v;
  31.  
  32.         rid.AddForce(direction.normalized*speed*Time.deltaTime);
  33.  
  34.         if (points >= 4)
  35.             wintext.text = "WIN!";
  36.        
  37.     }
  38.  
  39.     private void OnTriggerEnter(Collider other)
  40.     {
  41.         if (other.CompareTag("cube"))
  42.         {
  43.             points += 1;
  44.             other.gameObject.SetActive(false);
  45.             scoretext.text = "Score: " + points.ToString();
  46.         }
  47.     }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement