Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class Player : MonoBehaviour {
- public Rigidbody rid;
- public Vector3 direction;
- public float speed = 500f;
- public int points = 0;
- public timer pause;
- public Text wintext;
- public Text scoretext;
- public Joystick movejoystick;
- // Use this for initialization
- void Start () {
- rid = GetComponent<Rigidbody>();
- scoretext.text = "Score: " + points.ToString();
- wintext.text = "";
- }
- void Update () {
- float h = Input.GetAxis("Horizontal");
- float v = Input.GetAxis("Vertical");
- direction.x = h;
- direction.z = v;
- if (movejoystick.direction != Vector3.zero)
- {
- direction = movejoystick.direction;
- }
- rid.AddForce(direction.normalized * speed * Time.deltaTime);
- if (points >= 4)
- {
- wintext.text = "WIN!";
- pause.pausecolor();
- }
- }
- private void FixedUpdate()
- {
- rid.velocity = new Vector3(rid.velocity.x * 0.95f, rid.velocity.y, rid.velocity.z * 0.95f);
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.CompareTag("cube"))
- {
- points += 1;
- other.gameObject.SetActive(false);
- scoretext.text = "Score: " + points.ToString();
- }
- }
- }
Add Comment
Please, Sign In to add comment