CakeMeister

3d ball player extra

Aug 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 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 = 500f;
  12.     public int points = 0;
  13.     public timer pause;
  14.  
  15.     public Text wintext;
  16.     public Text scoretext;
  17.  
  18.     public Joystick movejoystick;
  19.     // Use this for initialization
  20.     void Start () {
  21.         rid = GetComponent<Rigidbody>();
  22.         scoretext.text = "Score: " + points.ToString();
  23.         wintext.text = "";
  24.     }
  25.    
  26.    
  27.     void Update () {
  28.         float h = Input.GetAxis("Horizontal");
  29.         float v = Input.GetAxis("Vertical");
  30.  
  31.         direction.x = h;
  32.         direction.z = v;
  33.  
  34.         if (movejoystick.direction != Vector3.zero)
  35.         {
  36.             direction = movejoystick.direction;
  37.         }
  38.         rid.AddForce(direction.normalized * speed * Time.deltaTime);
  39.  
  40.        
  41.         if (points >= 4)
  42.         {
  43.             wintext.text = "WIN!";
  44.             pause.pausecolor();
  45.         }
  46.            
  47.        
  48.     }
  49.  
  50.     private void FixedUpdate()
  51.     {
  52.         rid.velocity = new Vector3(rid.velocity.x * 0.95f, rid.velocity.y, rid.velocity.z * 0.95f);
  53.     }
  54.     private void OnTriggerEnter(Collider other)
  55.     {
  56.         if (other.CompareTag("cube"))
  57.         {
  58.             points += 1;
  59.             other.gameObject.SetActive(false);
  60.             scoretext.text = "Score: " + points.ToString();
  61.         }
  62.     }
  63.  
  64. }
Add Comment
Please, Sign In to add comment