Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Player : MonoBehaviour
- {
- // Spaceship Component
- Soul spaceship;
- public static int energy = 100;
- public int maxenergy = 100;
- IEnumerator Start()
- {
- EnergyCheck ();
- // Get the Spaceship component
- spaceship = GetComponent<Soul>();
- while (true)
- {
- // Make a bullet with the player’s position/rotation
- spaceship.Shot(transform);
- // Wait for shotDelay seconds.
- yield return new WaitForSeconds(spaceship.shotDelay);
- }
- }
- void Update()
- {
- // Right, Left
- float x = Input.GetAxisRaw("Horizontal");
- // Up, Down
- float y = Input.GetAxisRaw("Vertical");
- // Get the facing direction
- Vector2 direction = new Vector2(x, y).normalized;
- // Move
- spaceship.Move(direction);
- }
- // Called at the moment a collision happens
- void OnTriggerEnter2D(Collider2D c)
- {
- // Delete the bullet
- Destroy(c.gameObject);
- // Delete the player
- spaceship.Explosion();
- // Explode
- Destroy(gameObject);
- }
- void EnergyCheck(){
- System.Console.WriteLine (energy);
- if (energy <= 0) {
- //gameover
- }
- if (energy > maxenergy) {
- energy = maxenergy;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment