Advertisement
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 PlayerController : MonoBehaviour
- {
- public float speed;
- public Text countText;
- public Text timeText;
- public Text boostText;
- public Text winText;
- private Rigidbody2D rb2d;
- private int count;
- public int boostCount;
- private float timer;
- private double timeCompare;
- private float timeLeft;
- private int movSpeed;
- public float x;
- public float y;
- public float Health;
- private Vector2 movement;
- void Start()
- {
- rb2d = GetComponent<Rigidbody2D>();
- count = 0;
- speed = 0.5f;
- SetCountText();
- winText.text = " ";
- boostCount = 0;
- boostText.text = "Hit B to use your boost!";
- movSpeed = 0;
- Health = 100;
- }
- void FixedUpdate()
- {
- // movement, taken from the tutorial
- /* float moveHorizontal = Input.GetAxis("Horizontal");
- float moveVertical = Input.GetAxis("Vertical");
- Vector2 movement = new Vector2(moveHorizontal, moveVertical);
- rb2d.AddForce(movement * speed); */
- /* float moveHorizontal = Input.GetAxis("Horizontal");
- float moveVertical = Input.GetAxis("Vertical");
- Vector2 movement = new Vector2(moveHorizontal, moveVertical);
- rb2d.AddForce(movement * speed); */
- float inputX = Input.GetAxisRaw("Horizontal");
- float inputY = Input.GetAxisRaw("Vertical");
- movement = new Vector2(inputX, inputY);
- transform.Translate(movement * 50 * Time.deltaTime);
- // boost
- // How the boost works it when B is pressed it takes a time var
- timer = Mathf.Round(Time.time);
- if (Input.GetKeyDown(KeyCode.B) && boostCount == 0)
- {
- timeCompare = Mathf.Round(Time.fixedTime) + 5;
- boostCount = 1;
- };
- if (timer < timeCompare)
- {
- speed = 150;
- }
- if (timer > timeCompare)
- {
- speed = 100;
- }
- if(boostCount == 1)
- {
- boostText.text = "Boost was used!";
- }
- // debugging countText.text = "Count: " + count.ToString() + " " + speed.ToString() + " " + timer.ToString() + " " + (timeLeft) + " " + timeCompare;
- countText.text = "Speed: " + speed + "Weapon:";
- timeText.text = "Time: " + timer + " Health:" + Health;
- }
- void OnTriggerEnter2D(Collider2D other)
- {
- if (other.gameObject.CompareTag ("Pickup"))
- {
- other.gameObject.SetActive (false);
- count = count + 1;
- SetCountText();
- }
- }
- void SetCountText()
- {
- countText.text = "Count: " + speed.ToString() + timer.ToString();
- if(count >= 1)
- {
- winText.text = "You won!";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement