Fearsoulfire

playerscript new

Sep 2nd, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Player : MonoBehaviour
  5. {
  6. // Spaceship Component
  7. Soul spaceship;
  8. public static int energy = 100;
  9. public int maxenergy = 100;
  10.  
  11. IEnumerator Start()
  12. {
  13. EnergyCheck ();
  14. // Get the Spaceship component
  15. spaceship = GetComponent<Soul>();
  16.  
  17. while (true)
  18. {
  19.  
  20. // Make a bullet with the player’s position/rotation
  21. spaceship.Shot(transform);
  22.  
  23. // Wait for shotDelay seconds.
  24. yield return new WaitForSeconds(spaceship.shotDelay);
  25. }
  26. }
  27.  
  28. void Update()
  29. {
  30. // Right, Left
  31. float x = Input.GetAxisRaw("Horizontal");
  32.  
  33. // Up, Down
  34. float y = Input.GetAxisRaw("Vertical");
  35.  
  36. // Get the facing direction
  37. Vector2 direction = new Vector2(x, y).normalized;
  38.  
  39. // Move
  40. spaceship.Move(direction);
  41. }
  42.  
  43. // Called at the moment a collision happens
  44. void OnTriggerEnter2D(Collider2D c)
  45. {
  46. // Delete the bullet
  47. Destroy(c.gameObject);
  48.  
  49. // Delete the player
  50. spaceship.Explosion();
  51.  
  52. // Explode
  53. Destroy(gameObject);
  54. }
  55. void EnergyCheck(){
  56. System.Console.WriteLine (energy);
  57. if (energy <= 0) {
  58. //gameover
  59. }
  60. if (energy > maxenergy) {
  61. energy = maxenergy;
  62. }
  63.  
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment