Advertisement
Guest User

Untitled

a guest
Sep 6th, 2015
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4.  
  5.  
  6. public class PlayerController : MonoBehaviour {
  7.  
  8. public float speed;
  9. public Text countText;
  10. public float force = 8.0f;
  11.  
  12. private Rigidbody rb;
  13. private int count;
  14.  
  15. TimerController timerController;
  16.  
  17. void Start ()
  18. {
  19. rb = GetComponent<Rigidbody>();
  20. count = 0;
  21. SetCountText ();
  22.  
  23. timerController = GameObject.FindObjectOfType<TimerController>();
  24. }
  25.  
  26. void FixedUpdate()
  27. {
  28. if (SystemInfo.deviceType == DeviceType.Desktop)
  29. {
  30. float moveHorizontal = Input.GetAxis ("Horizontal");
  31. float moveVertical = Input.GetAxis ("Vertical");
  32.  
  33. Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
  34.  
  35. rb.AddForce (movement * speed);
  36. }
  37. else
  38. {
  39. Vector3 movement = new Vector3 (Input.acceleration.x, 0.0f, Input.acceleration.y);
  40. rb.AddForce (movement * speed);
  41. }
  42. }
  43.  
  44. void OnTriggerEnter(Collider other)
  45. {
  46. if (other.gameObject.CompareTag("Pick Up"))
  47. {
  48. other.gameObject.SetActive (false);
  49. count = count + 1;
  50. SetCountText ();
  51. timerController.AddToTimer(3f);
  52. }
  53. }
  54.  
  55. void SetCountText ()
  56. {
  57. countText.text = "Count: " + count.ToString ();
  58.  
  59. }
  60. public void ChangeSpeed(float s)
  61. {
  62. speed = s;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement