Advertisement
Guest User

unity c# help

a guest
Feb 6th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6.  
  7. public class PlayerController : MonoBehaviour
  8. {
  9.  
  10.     public Text speedtext;
  11.     public Text countext;
  12.     public Text bumptext;
  13.     public float startspeed;
  14.  
  15.     private Rigidbody2D rb2d;
  16.     private int count;
  17.     private int bumpcount;
  18.     private float speedmultiplier;
  19.     private Vector2 ufovelocity;
  20.  
  21.     // Start is called before the first frame update
  22.     void Start()
  23.     {
  24.         rb2d = GetComponent<Rigidbody2D>();
  25.         count = 0;
  26.         SetCountext();
  27.         speedmultiplier = 1;
  28.         Setspeedtext();
  29.         bumpcount = 0;
  30.         Setbumptext();
  31.     }
  32.  
  33.     // Update is called once per frame
  34.     void FixedUpdate()
  35.     {
  36.         float movex = Input.GetAxis("Horizontal");
  37.         float movey = Input.GetAxis("Vertical");
  38.  
  39.         Vector2 movexy = new Vector2(movex, movey);
  40.  
  41.         rb2d.AddForce(movexy * startspeed * speedmultiplier);
  42.  
  43.     }
  44.  
  45.     private void OnCollisionEnter2d(Collision2D col)
  46.     {
  47.         if (col.gameObject.CompareTag("Wall"))
  48.         {
  49.             bumpcount++;
  50.             Setbumptext();
  51.         }
  52.     }
  53.  
  54.     private void OnTriggerEnter2D(Collider2D other)
  55.     {
  56.         if (other.gameObject.CompareTag("PickUp"))
  57.         {
  58.             other.gameObject.SetActive(false);
  59.             count++;
  60.             SetCountext();
  61.             speedmultiplier = speedmultiplier + 1;
  62.             Setspeedtext();
  63.         }
  64.     }
  65.  
  66.     void SetCountext()
  67.     {
  68.         countext.text = "Count = " + count.ToString();
  69.     }
  70.     void Setspeedtext()
  71.     {
  72.         speedtext.text = "Speed multiplier = " + speedmultiplier.ToString();
  73.     }
  74.     void Setbumptext()
  75.     {
  76.         bumptext.text = "Wall bumps = " + bumpcount.ToString();
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement