using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GameMag : MonoBehaviour
{
public SpriteRenderer KBBImage;
public SpriteRenderer KawiImage;
public SpriteRenderer BawiImage;
public SpriteRenderer BoImage;
public Text resultText;
public Sprite[] kbbimages;
public bool isStart = false;
void Start() { }
void Update() { }
public void OnGameStartBtnClick()
{
Debug.Log("게임 스타트 버튼 클릭");
if (isStart) return;
isStart = true;
StartCoroutine("KBBTimer");
}
public void OnKawiBtnClick()
{
KawiImage.color = Color.white;
isStart = false;
playerKBB = 0;
GameResult();
}
public void OnBawiBtnClick()
{
isStart = false;
playerKBB = 1;
GameResult();
}
public void OnBoBtnClick()
{
isStart = false;
playerKBB = 2;
GameResult();
}
public int imageNumber = 0;
IEnumerator KBBTimer()
{
while (isStart)
{
KBBImage.sprite = kbbimages[imageNumber++];
yield return new WaitForSeconds(0.1f);
if (imageNumber >= 3) imageNumber = 0;
}
}
public int comKBB = 0;
public int playerKBB = 0;
public void GameResult()
{
comKBB = Random.Range(0, 3);
KBBImage.sprite = kbbimages[comKBB];
Debug.Log("컴퓨터 : " +comKBB);
Debug.Log("플레이어 : " + playerKBB);
if (comKBB == playerKBB)
{
resultText.text = "DRAW!";
Debug.Log("컴퓨터와 플레이어 무승부");
}
else if ((playerKBB == 0 && comKBB == 2) ||
(playerKBB == 1 && comKBB == 0) ||
(playerKBB == 2 && comKBB == 1))
{
resultText.text = "YOU WIN!";
Debug.Log("플레이어 승!");
}
else
{
resultText.text = "YOU LOSE!";
Debug.Log("플레이어 패배!"); ;
}
}
}
===============================================================================================
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class CPinkMon : MonoBehaviour {
public Transform[] positions;
public Text countText;
int score = 0;
void Start () {
gameObject.transform.position = positions[0].position;
StartCoroutine("MoveTimer");
}
IEnumerator MoveTimer()
{
while (true)
{
yield return new WaitForSeconds(0.5f);
int postNum = Random.Range(0, 6);
transform.position = positions[postNum].position;
}
}
void OnMouseDown()
{
score++;
countText.text = score.ToString();
StartCoroutine("ClickColorChange");
}
IEnumerator ClickColorChange()
{
GetComponent<SpriteRenderer>().material.color =
new Color(1f, 0.5f, 0.5f, 0.5f);
yield return new WaitForSeconds(0.08f);
GetComponent<SpriteRenderer>().material.color = new Color(1f, 1f, 1f, 1f);
}
void Update () {
}
}
댓글
댓글 쓰기