slimecing

a fighting game featuring slimes and swords
Log | Files | Refs | README

StageSelect.cs (1503B)


      1 using System.Collections;
      2 using System.Collections.Generic;
      3 using UnityEngine;
      4 using UnityEngine.UI;
      5 
      6 public class StageSelect : MonoBehaviour
      7 {
      8     public Sprite[] stages;
      9     public GameObject stageImage;
     10     public GameObject playerSelect;
     11     private float nextTime = 0;
     12 
     13     private int currentStage;
     14     private Image img;
     15 
     16     void Start()
     17     {
     18         Screen.SetResolution(Screen.currentResolution.width, Screen.currentResolution.height, true);
     19         img = stageImage.GetComponent<Image>();
     20     }
     21 
     22     void Update()
     23     {
     24         if (Input.GetAxis("GlobalHorizontal") >= 0.5 && Time.time > nextTime)
     25         {
     26             nextStage();
     27             nextTime = Time.time + 0.5f;
     28         }
     29         else if (Input.GetAxis("GlobalHorizontal") <= -0.5 && Time.time > nextTime)
     30         {
     31             lastStage();
     32             nextTime = Time.time + 0.5f;
     33         }
     34     }
     35 
     36     public void lastStage()
     37     {
     38         currentStage--;
     39         if(currentStage < 0)
     40         {
     41             currentStage = stages.Length - 1;
     42         }
     43         img.sprite = stages[currentStage];
     44     }
     45 
     46     public void nextStage()
     47     {
     48         currentStage++;
     49         if(currentStage > stages.Length - 1)
     50         {
     51             currentStage = 0;
     52         }
     53         img.sprite = stages[currentStage];
     54     }
     55 
     56     public void stageSelected()
     57     {
     58         playerSelect.SetActive(true);
     59         playerSelect.GetComponent<ReadyScript>().stage = currentStage + 2;
     60         playerSelect.GetComponent<ReadyScript>().stageOff();
     61     }
     62 }