Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.68 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class HighlightAndBehaviour : MonoBehaviour
  6. {
  7.  
  8.     [SerializeField] Choice currentChoice;
  9.  
  10.     [SerializeField] Sprite startNormal, startHover, startPressed;
  11.     [SerializeField] Sprite creditsNormal, creditsHover, creditsPressed;
  12.     [SerializeField] Sprite exitNormal, exitHover, exitPressed;
  13.     [SerializeField] SpriteRenderer startSR, creditsSR, exitSR;
  14.  
  15.  
  16.     void Start()
  17.     {
  18.         StartCoroutine(StartChoice());
  19.     }
  20.  
  21.  
  22.     IEnumerator StartChoice()
  23.     {
  24.         while(currentChoice == Choice.Start)
  25.         {
  26.             startSR.sprite = startHover;
  27.             if(Input.GetKeyDown(KeyCode.Return))
  28.             {
  29.                 startSR.sprite = startPressed;
  30.                 // MOVE TO SCENE HERE
  31.                 currentChoice = Choice.Null;
  32.             }
  33.             if(Input.GetKeyDown(KeyCode.DownArrow))
  34.             {
  35.                 startSR.sprite = startNormal;
  36.                 currentChoice = Choice.Credits;
  37.                 StartCoroutine(CreditsChoice());
  38.             }
  39.  
  40.             yield return null;
  41.         }
  42.     }
  43.     IEnumerator CreditsChoice()
  44.     {
  45.         while (currentChoice == Choice.Credits)
  46.         {
  47.             creditsSR.sprite = creditsHover;
  48.             if (Input.GetKeyDown(KeyCode.Return))
  49.             {
  50.                 creditsSR.sprite = creditsPressed;
  51.                 // MOVE TO CREDITS HERE
  52.                 currentChoice = Choice.Null;
  53.             }
  54.             if (Input.GetKeyDown(KeyCode.DownArrow))
  55.             {
  56.                 creditsSR.sprite = creditsNormal;
  57.                 currentChoice = Choice.Exit;
  58.                 StartCoroutine(ExitChoice());
  59.             }
  60.             if (Input.GetKeyDown(KeyCode.UpArrow))
  61.             {
  62.                 creditsSR.sprite = creditsNormal;
  63.                 currentChoice = Choice.Start;
  64.                 StartCoroutine(StartChoice());
  65.             }
  66.  
  67.             yield return null;
  68.         }
  69.     }
  70.     IEnumerator ExitChoice()
  71.     {
  72.         while (currentChoice == Choice.Exit)
  73.         {
  74.             exitSR.sprite = exitHover;
  75.             if (Input.GetKeyDown(KeyCode.Return))
  76.             {
  77.                 exitSR.sprite = exitPressed;
  78.                 // EXIT GAME HERE
  79.                 currentChoice = Choice.Null;
  80.             }
  81.             if (Input.GetKeyDown(KeyCode.UpArrow))
  82.             {
  83.                 exitSR.sprite = exitNormal;
  84.                 currentChoice = Choice.Credits;
  85.                 StartCoroutine(CreditsChoice());
  86.             }
  87.             yield return null;
  88.         }
  89.     }
  90.  
  91.  
  92. }
  93.  
  94.  
  95. public enum Choice
  96. {
  97.     Start,
  98.     Credits,
  99.     Exit,
  100.     Null
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement