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 Text speedtext;
- public Text countext;
- public Text bumptext;
- public float startspeed;
- private Rigidbody2D rb2d;
- private int count;
- private int bumpcount;
- private float speedmultiplier;
- private Vector2 ufovelocity;
- // Start is called before the first frame update
- void Start()
- {
- rb2d = GetComponent<Rigidbody2D>();
- count = 0;
- SetCountext();
- speedmultiplier = 1;
- Setspeedtext();
- bumpcount = 0;
- Setbumptext();
- }
- // Update is called once per frame
- void FixedUpdate()
- {
- float movex = Input.GetAxis("Horizontal");
- float movey = Input.GetAxis("Vertical");
- Vector2 movexy = new Vector2(movex, movey);
- rb2d.AddForce(movexy * startspeed * speedmultiplier);
- }
- private void OnCollisionEnter2d(Collision2D col)
- {
- if (col.gameObject.CompareTag("Wall"))
- {
- bumpcount++;
- Setbumptext();
- }
- }
- private void OnTriggerEnter2D(Collider2D other)
- {
- if (other.gameObject.CompareTag("PickUp"))
- {
- other.gameObject.SetActive(false);
- count++;
- SetCountext();
- speedmultiplier = speedmultiplier + 1;
- Setspeedtext();
- }
- }
- void SetCountext()
- {
- countext.text = "Count = " + count.ToString();
- }
- void Setspeedtext()
- {
- speedtext.text = "Speed multiplier = " + speedmultiplier.ToString();
- }
- void Setbumptext()
- {
- bumptext.text = "Wall bumps = " + bumpcount.ToString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement