Advertisement
Guest User

Untitled

a guest
Aug 16th, 2015
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. using System.Collections;
  2.  
  3. public class Player : MonoBehaviour {
  4. public GameManager manager;
  5. public float moveSpeed;
  6. public GameObject deathParticles;
  7. public bool usesManager = true;
  8.  
  9. private float maxSpeed = 6f;
  10. private Vector3 input;
  11.  
  12. private Vector3 spawn;
  13.  
  14. public AudioClip[] audioClip;
  15.  
  16.  
  17. // Use this for initialization
  18. void Start () {
  19. spawn = transform.position;
  20. if(usesManager)
  21. {
  22. manager = manager.GetComponent<GameManager>();
  23. }
  24.  
  25. }
  26.  
  27. void FixedUpdate () {
  28. input = new Vector3(Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical"));
  29. if (rigidbody.velocity.magnitude < maxSpeed)
  30. {
  31. rigidbody.AddRelativeForce (input * moveSpeed);
  32. }
  33.  
  34. if (transform.position.y < -2)
  35. {
  36. Die ();
  37. }
  38. }
  39.  
  40. void OnCollisionEnter(Collision other)
  41. {
  42. if (other.transform.tag == "Enemy")
  43. {
  44. Die();
  45. }
  46.  
  47. }
  48.  
  49. void OnTriggerEnter(Collider other)
  50. {
  51.  
  52. if (other.transform.tag == "Enemy"){
  53. PlaySound (2);
  54. Die();
  55. }
  56. if (other.transform.tag == "Token"){
  57. if(usesManager)
  58. {
  59. manager.tokenCount += 1;
  60. }
  61.  
  62. PlaySound (0);
  63. Destroy(other.gameObject);
  64. }
  65. if (other.transform.tag == "Goal")
  66. {
  67. PlaySound (1);
  68. Time.timeScale = 0f;
  69. manager.CompleteLevel();
  70.  
  71. }
  72. }
  73. void PlaySound(int clip)
  74. {
  75. audio.clip = audioClip [clip];
  76. audio.Play ();
  77. }
  78.  
  79. void Die()
  80. {
  81. Instantiate(deathParticles, transform.position, Quaternion.Euler (270,0,0));
  82. transform.position = spawn;
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement