Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. using UnityStandardAssets.Characters.FirstPerson;
  5.  
  6. public class Player : MonoBehaviour
  7. {
  8.  
  9. public AudioClip[] audioClip;
  10.  
  11. int rayLength = 5;
  12. bool Pickup_Pressed = false;
  13. float delay = 3.0f;
  14.  
  15. public FirstPersonController fpscontroller;
  16. public WeaponSwitch wepswitch;
  17.  
  18. bool HasTommy = false;
  19. bool HasAxe = false;
  20.  
  21. public int foodLevel = 0;
  22. String foodLevelText = "0";
  23.  
  24. // Use this for initialization
  25. void Start ()
  26. {
  27.  
  28. }
  29.  
  30.  
  31. // Update is called once per frame
  32. void Update ()
  33. {
  34. PickUpItems();
  35. CheckWhatGun();
  36. WeaponSwitchingScroll();
  37. }
  38.  
  39. void OnTriggerEnter(Collider Col)
  40. {
  41. if (Col.tag == "weapon")
  42. {
  43. Debug.Log("You picked a weapon!");
  44. PlaySound(1);
  45. Destroy(Col.gameObject);
  46. wepswitch.Gun_Switch_Tommygun.SetActive(true);
  47. HasTommy = true;
  48. }
  49. }
  50.  
  51. public void PlaySound(int clip)
  52. {
  53. AudioSource audio = GetComponent<AudioSource>();
  54. audio.clip = audioClip[clip];
  55. audio.Play();
  56. }
  57.  
  58. void PickUpItems()
  59. {
  60. RaycastHit hit;
  61. var fwd = transform.TransformDirection(Vector3.forward);
  62.  
  63. if (Physics.Raycast(transform.position, fwd, out hit, rayLength))
  64. {
  65. if (hit.collider.gameObject.tag == "food")
  66. {
  67. if (Input.GetKeyDown("e"))
  68. {
  69. if(Pickup_Pressed == false)
  70. {
  71. Destroy(hit.collider.gameObject);
  72. StartCoroutine(MyMethod());
  73. PlaySound(0);
  74. Pickup_Pressed = true;
  75. }
  76. Destroy(hit.collider.gameObject, delay);
  77. }
  78. }
  79. if (hit.collider.gameObject.tag == "axe")
  80. {
  81. if (Input.GetKeyDown("e"))
  82. {
  83. wepswitch.Gun_Switch_Axe.SetActive(true);
  84. HasAxe = true;
  85. PlaySound(1);
  86. Destroy(hit.collider.gameObject);
  87. }
  88. }
  89. }
  90. }
  91. IEnumerator MyMethod()
  92. {
  93. Debug.Log("Before Waiting 2 seconds");
  94. fpscontroller.m_WalkSpeed = 0;
  95. yield return new WaitForSeconds(3);
  96. Debug.Log("After Waiting 2 Seconds");
  97. fpscontroller.m_WalkSpeed = 5;
  98. foodLevel += 5;
  99. }
  100. void CheckWhatGun()
  101. {
  102. if (HasTommy == true)
  103. {
  104. if(HasAxe == true)
  105. {
  106. wepswitch.Gun_Switch_Tommygun.SetActive(false);
  107. HasTommy = false;
  108. }
  109. }
  110. if (HasAxe == true)
  111. {
  112. if(HasTommy == true)
  113. {
  114. wepswitch.Gun_Switch_Axe.SetActive(false);
  115. HasTommy = true;
  116. }
  117. }
  118. }
  119. void WeaponSwitchingScroll()
  120. {
  121. if(HasAxe == true && HasTommy == true)
  122. {
  123. if (Input.GetKeyDown("q"))
  124. {
  125. wepswitch.Gun_Switch_Tommygun.SetActive(false);
  126. }
  127. else if (Input.GetKeyDown("f"))
  128. {
  129. wepswitch.Gun_Switch_Axe.SetActive(false);
  130. }
  131. }
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement