Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- public class PlayerController : MonoBehaviour {
- public float speed;
- public Text countText;
- public float force = 8.0f;
- private Rigidbody rb;
- private int count;
- TimerController timerController;
- void Start ()
- {
- rb = GetComponent<Rigidbody>();
- count = 0;
- SetCountText ();
- timerController = GameObject.FindObjectOfType<TimerController>();
- }
- void FixedUpdate()
- {
- if (SystemInfo.deviceType == DeviceType.Desktop)
- {
- float moveHorizontal = Input.GetAxis ("Horizontal");
- float moveVertical = Input.GetAxis ("Vertical");
- Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
- rb.AddForce (movement * speed);
- }
- else
- {
- Vector3 movement = new Vector3 (Input.acceleration.x, 0.0f, Input.acceleration.y);
- rb.AddForce (movement * speed);
- }
- }
- void OnTriggerEnter(Collider other)
- {
- if (other.gameObject.CompareTag("Pick Up"))
- {
- other.gameObject.SetActive (false);
- count = count + 1;
- SetCountText ();
- timerController.AddToTimer(3f);
- }
- }
- void SetCountText ()
- {
- countText.text = "Count: " + count.ToString ();
- }
- public void ChangeSpeed(float s)
- {
- speed = s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement