카운트 다운 구현(1) - 게임시작 전 카운트 |
게임을 시작할 때 , 3,2,1 GO! 라는 문구를 구현해보겠습니다.
그냥 씬을 들어가서 바로 선택해도 되지만....그래야 왠지 더 긴장이 될지도???
GM스크립트로 다시 이동해봅니다.
여기서 카운트와 관련된 변수를 추가해주고, 또 코루틴을 사용하여 3,2,1,GO가 움직(?)이는 것을 구현할 것입니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | using UnityEngine; using System.Collections; public class GM : MonoBehaviour { //유저와 적의 이미지(8강) public UISprite player_Img; public UISprite enemy_Img; //카운트 이미지 public UISprite count_Img; // Use this for initialization void Start () { //카운트 코루틴 호출 StartCoroutine(Count()); } // Update is called once per frame void Update () { } //카운트 코루틴 IEnumerator Count() { count_Img.spriteName = "3"; yield return new WaitForSeconds(1.0f); count_Img.spriteName = "2"; yield return new WaitForSeconds(1.0f); count_Img.spriteName = "1"; yield return new WaitForSeconds(1.0f); count_Img.spriteName = "Go"; } //유저가 버튼을 눌러 이미지를 변경하는 메소드 모음 void PlayerButtonImgChange_Ga() { player_Img.spriteName = "Ga"; } void PlayerButtonImgChange_Ba() { player_Img.spriteName = "Ba"; } void PlayerButtonImgChange_Bo() { player_Img.spriteName = "Boouo"; } } | cs |
이번에는 주석을 달아놓았으니, 모든 코드를 복사 후 GM 스크립트에 붙혀넣기 하시면 됩니다.
사실 어려운 것이 하나도 없기 때문에...직접 보시면서 파악하시면 됩니다.
아까처럼 추가가 되었기 때문에 이미지를 끌어서 넣어줍니다.
끌어다 넣은 후 플레이를 하시면, 가운데 숫자가 카운트가 되면서 GO!!!라고 되는 것을 보실 수 있을 것입니다.
카운트 다운 구현(2) - UI 버튼 띄우기 |
GO!!!라는 이미지가 띄워진 후에 게임을 시작하도록 구현할 것입니다.
이제 이렇게 바꿀 것입니다.
일단 위와같이 유저의 버튼을 모두 꺼줍니다.
그리고 GM스크립트를 아래와 같이 짜줄 것입니다.
주석을 달아놓을 것이고...코드 전체를 복사 붙혀넣기 하시면 됩니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | using UnityEngine; using System.Collections; public class GM : MonoBehaviour { //유저와 적의 이미지(8강) public UISprite player_Img; public UISprite enemy_Img; //카운트 이미지 public UISprite count_Img; //유저의 버튼 public GameObject player_Ga_Button; public GameObject player_Ba_Button; public GameObject player_Bo_Button; //승부 버튼 public GameObject stop_Button; // Use this for initialization void Start () { //카운트 코루틴 호출 StartCoroutine(Count()); } // Update is called once per frame void Update () { } //카운트 코루틴 IEnumerator Count() { count_Img.spriteName = "3"; yield return new WaitForSeconds(1.0f); count_Img.spriteName = "2"; yield return new WaitForSeconds(1.0f); count_Img.spriteName = "1"; yield return new WaitForSeconds(1.0f); count_Img.spriteName = "Go"; //시작된 이후에는, 가위바위보 선택버튼과 승부 버튼을 On 해준다. player_Ga_Button.gameObject.SetActive(true); player_Ba_Button.gameObject.SetActive(true); player_Bo_Button.gameObject.SetActive(true); stop_Button.gameObject.SetActive(true); } //유저가 버튼을 눌러 이미지를 변경하는 메소드 모음 void PlayerButtonImgChange_Ga() { player_Img.spriteName = "Ga"; } void PlayerButtonImgChange_Ba() { player_Img.spriteName = "Ba"; } void PlayerButtonImgChange_Bo() { player_Img.spriteName = "Boouo"; } } | cs |
이렇게 코드를 추가한 후에, 아래와같이 오브젝트를 맞춰서 연결해줍니다.
이렇게 연결 한 후에 플레이를 하면
카운트 다운이 된 다음에 GO!라는 이미지가 나오면 바로 선택할 수 있는 버튼과 승부를 진행할 수 있는 버튼이 생깁니다.
다음검색