반응형
코드 작성
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class WormGame : MonoBehaviour
{
public Text wormsText;
public Text clicksText;
public Text timeElapsedText;
public int worms;
public int clicks;
public float timeElapsed;
void Start()
{
worms = 0;
clicks = 0;
timeElapsed = 0f;
}
void Update()
{
wormsText.text = "Worms: " + worms.ToString();
clicksText.text = "Clicks: " + clicks.ToString();
timeElapsedText.text = "Time Elapsed: " + timeElapsed.ToString("F1") + " seconds";
if (worms >= 100)
{
Debug.Log("You win!");
enabled = false;
}
}
public void CollectWorms()
{
worms++;
clicks++;
}
public void WaitForReproduction()
{
worms += Random.Range(1, 4);
clicks++;
StartCoroutine(WaitForOneSecond());
}
IEnumerator WaitForOneSecond()
{
yield return new WaitForSeconds(1f);
timeElapsed += 1f;
}
public void WormDeath()
{
if (Random.Range(0f, 1f) < 0.05f)
{
worms--;
Debug.Log("Oh no! A worm has died.");
}
}
}
의뢰하기
반응형