Advertisement
Fearsoulfire

bug

Oct 14th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.48 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class DubPlayer : MonoBehaviour
  5. {
  6.  
  7. //public static bool carrotboost = false;
  8. public static float energy = 500;
  9. public static bool boostActive;
  10. bool isplaying;
  11.  
  12. //Boost atack
  13. public float boost = 1500f;
  14.  
  15. //Soul Component
  16. Soul soul;
  17.  
  18. //Enemy component
  19. Enemy enemy;
  20.  
  21. //Manager component
  22. Manager manager;
  23.  
  24. //Bullet component
  25. Bullet bullet;
  26. public GameObject Title;
  27.  
  28.  
  29. // Call a coroutine inside the Start method
  30. IEnumerator Start()
  31. {
  32. energy = 500;
  33. Title = GameObject.Find ("Title");
  34.  
  35. /*if (carrotboost == true)
  36. CarrotBoost();*/
  37.  
  38. //Get soul component
  39. soul = GetComponent<Soul>();
  40.  
  41. while (true)
  42. {
  43.  
  44. // Make the bullet or power, using the player's position
  45. soul.Shot(transform);
  46.  
  47. // Play the shot sound effect
  48. audio.Play();
  49.  
  50. // Wait for shotDelay seconds
  51. yield return new WaitForSeconds(soul.shotDelay);
  52.  
  53. }
  54. }
  55.  
  56. // For determining which way the player is currently facing.
  57. [HideInInspector]
  58. public bool facingRight = true;
  59.  
  60. // Summon animator
  61. Animator animator;
  62. public bool flying;
  63.  
  64.  
  65. void Update()
  66. {
  67. //animator.SetBool("flying", true);
  68. if (gameObject.layer != LayerMask.NameToLayer("Boost"))
  69. gameObject.layer = LayerMask.NameToLayer("Boost");
  70.  
  71.  
  72.  
  73. //When Players reaches desired (L/R) possition make him stop
  74. if (transform.position.x <= -7.5f)
  75. transform.position = new Vector3(-7.5f, transform.position.y, transform.position.z);
  76. else if (transform.position.x >= 20.5f)
  77. transform.position = new Vector3(20.5f, transform.position.y, transform.position.z);
  78.  
  79. //When Players reaches desired (U/P) possition make him stop
  80. if (transform.position.y <= -6f)
  81. transform.position = new Vector3(transform.position.x, -6f, transform.position.z);
  82. else if (transform.position.y >= 3f)
  83. transform.position = new Vector3(transform.position.x, 3f, transform.position.z);
  84.  
  85. //Get animator
  86. animator = GetComponent<Animator>();
  87.  
  88. //Boost condition
  89. {
  90. /*
  91. if (carrotboost)
  92. CarrotBoost();*/
  93. //boostActive = Input.GetButton("Fire1");
  94.  
  95. if (boostActive)
  96. {
  97. //Drain energy
  98.  
  99. energy -= 1;
  100.  
  101. //Player dash
  102. animator.SetBool("flying", true);
  103. rigidbody2D.AddForce(new Vector2(0, boost));
  104.  
  105. //Change layer type
  106. gameObject.layer = LayerMask.NameToLayer("Boost");
  107. //Delete the player
  108. //soul.Explosion();
  109.  
  110. /*Explode
  111. Destroy(gameObject);*/
  112.  
  113. // Play the shot sound effect
  114. if (isplaying == false)
  115. {
  116. audio.Play();
  117. isplaying = true;
  118. }
  119.  
  120. }
  121. else
  122. {
  123. //Make player back to normal state
  124. animator.SetBool("flying", false);
  125.  
  126. //Back to normal layer
  127. gameObject.layer = LayerMask.NameToLayer("Player");
  128. isplaying = false;
  129. }
  130. if (energy <= 0)
  131. {
  132. Application.LoadLevel (Application.loadedLevel);
  133. soul.Explosion();
  134. Destroy(gameObject);
  135.  
  136. }
  137. if (energy > 500)
  138. energy = 500;
  139. energy = energy - 1*Time.deltaTime;
  140.  
  141. }
  142.  
  143. // Cache the horizontal input.
  144. float h = Input.GetAxis("Horizontal");
  145.  
  146. // If the input is moving the player right and the player is facing left...
  147. if (h > 0 && !facingRight)
  148. // ... flip the player.
  149. Flip();
  150. // Otherwise if the input is moving the player left and the player is facing right...
  151. else if (h < 0 && facingRight)
  152. // ... flip the player.
  153. Flip();
  154.  
  155. // Move left and right
  156. float x = Input.GetAxisRaw("Horizontal");
  157.  
  158. // Move up and down
  159. float y = Input.GetAxisRaw("Vertical");
  160.  
  161. // Get the direction of movement
  162. Vector2 direction = new Vector2(x, y).normalized;
  163.  
  164. // Move
  165. soul.Move(direction);
  166. // while bunny is alive
  167. energy -= (1 * Time.deltaTime);
  168. }
  169.  
  170. // Bunny movement
  171. void Move(Vector2 direction)
  172. {
  173. // Get the lower-left world coordinate of the viewport.
  174. Vector2 min = Camera.main.ViewportToWorldPoint(new Vector2(0, 0));
  175.  
  176. // Get the upper-right world coordinate of the viewport.
  177. Vector2 max = Camera.main.ViewportToWorldPoint(new Vector2(1, 1));
  178.  
  179. // Get the coordinates of the player
  180. Vector2 pos = transform.position;
  181.  
  182. // Move by the proper amount
  183. pos += direction * soul.speed * Time.deltaTime;
  184.  
  185. // Restrict the player from moving outside of the screen.
  186. pos.x = Mathf.Clamp(pos.x, min.x, max.x);
  187. pos.y = Mathf.Clamp(pos.y, min.y, max.y);
  188.  
  189. // Assign the newly-restricted position value.
  190. transform.position = pos;
  191. }
  192.  
  193.  
  194. // Called when collision happens
  195. void OnTriggerEnter2D(Collider2D c)
  196. {
  197. if (boostActive)
  198. {
  199.  
  200. }
  201. else
  202. {
  203. //Get the Layer name
  204. string layerName = LayerMask.LayerToName(c.gameObject.layer);
  205.  
  206. // Delete the bullet, if it's in the "bullet (enemy)" layer
  207. if (layerName == "Bullet (Enemycorn)")
  208. {
  209. //Energy goes to zero
  210. soul.Explosion();
  211.  
  212. //Delete the bullet
  213. Destroy(c.gameObject);
  214. }
  215.  
  216. //Create an explosion if the layer is "Bullet (Enemy)" or "Enemy"
  217. if (layerName == "Bullet(Enemycorn)" || layerName == "Enemy" || layerName == "Enemycorn" || layerName == "Enemybullet")
  218. {
  219.  
  220. // Find and acquire the Manager component within the scene, and call the GameOver method.
  221. FindObjectOfType<Manager>().GameOver();
  222. Application.LoadLevel (Application.loadedLevel);
  223.  
  224. // Explode
  225. Destroy(gameObject);
  226.  
  227. //Delete the player
  228. soul.Explosion();
  229. }
  230. }
  231. }
  232.  
  233. void Flip()
  234. {
  235. // Switch the way the player is labelled as facing.
  236. facingRight = !facingRight;
  237.  
  238. // Multiply the player's x local scale by -1.
  239. Vector3 theScale = transform.localScale;
  240. theScale.x *= -1;
  241. transform.localScale = theScale;
  242. }
  243. /*public void CarrotBoost()
  244. {
  245. for (float contador = 0; contador < 1; contador += 1)
  246. {
  247. animator = GetComponent<Animator>();
  248. //Change layer type
  249. gameObject.layer = LayerMask.NameToLayer("Boost");
  250. energy += 5;
  251. //Player dash
  252. animator.SetBool("flying", true);
  253. rigidbody2D.AddForce(new Vector2(0, 1780f));
  254.  
  255.  
  256. //Explosion
  257. soul.Explosion();
  258.  
  259. audio.Play();
  260. }
  261.  
  262.  
  263.  
  264.  
  265. // ----------------------------------
  266. //player back to normal state
  267.  
  268. animator.SetBool("flying", false);
  269.  
  270. //Back to normal layer
  271. gameObject.layer = LayerMask.NameToLayer("Player");
  272.  
  273. }
  274.  
  275. */
  276. }
  277. //public bool boostActive { get; set; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement