권은령

add partial code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public enum GameState
{
Ready,
Play,
End
}
public class MiniGameManager : MonoBehaviour
{
public List<Rabbit> m_rabbits;
static public GameState gameState;
public GameObject UIButton;
public Text timeText;
public Text scoreText;
private int score = 0;
private float time = 0f;
private float sec = 0f;
private int playTime = 30;
void Start()
{
SetSceneReady();
}
public void SetSceneReady()
{
gameState = GameState.Ready;
timeText.text = "00 : " + playTime.ToString("D2");
ResetRabbits();
}
public void LoadMainScene()
{
// 로딩바?
SceneManager.LoadScene("Main");
}
void ResetRabbits()
{
for (int i = 0; i < m_rabbits.Count; i++)
{
m_rabbits[i].None();
}
}
void ExitRabbits()
{
for (int i = 0; i < m_rabbits.Count; i++)
{
if (m_rabbits[i].state != RabbitState.Die && m_rabbits[i].state != RabbitState.None)
m_rabbits[i].Exit();
}
}
public void ShowScore()
{
gameState = GameState.End;
scoreText.text = score + " 마리를 잡았습니다!";
SetGamePanel.Instance.SetPanelOn();
scoreText.gameObject.SetActive(true);
UIButton.SetActive(true);
}
void Update()
{
if (gameState == GameState.Play)
{
time += Time.deltaTime;
sec = Mathf.Ceil(playTime - time);
timeText.text = "00 : " + ((int)sec).ToString("D2");
if (sec <= 0)
{
ExitRabbits();
ShowScore();
}
if (Input.GetMouseButtonDown(0))
{
Vector2 touchPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast(touchPos, Vector2.zero);
if (hit)
{
int num = int.Parse(hit.collider.gameObject.name);
if (m_rabbits[num].state == RabbitState.Idle)
{
score += 1;
m_rabbits[num].Die();
}
}
}
}
else
return;
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: b7bf6ddfa7f5fbc48a99b433ef28c68a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum RabbitState
{
None,
Pop,
Idle,
Die,
Exit
}
public class Rabbit : MonoBehaviour
{
private Animator m_animator;
public RabbitState state = RabbitState.None;
public GameObject body;
private float m_resetTime = 0f;
private float m_exitTime = 0f;
private void Awake()
{
m_animator = GetComponent<Animator>();
SetResetTime();
}
private void SetResetTime()
{
m_resetTime = Random.Range(1.5f, 6f);
}
public void None()
{
state = RabbitState.None;
body.SetActive(false);
m_animator.SetBool("dying", false);
m_animator.SetBool("exiting", false);
SetResetTime();
}
public void Pop()
{
state = RabbitState.Pop;
body.SetActive(true);
m_animator.SetBool("poping", true);
}
public void Idle()
{
state = RabbitState.Idle;
m_animator.SetBool("poping", false);
}
public void Die()
{
state = RabbitState.Die;
m_animator.SetBool("dying", true);
}
public void Exit()
{
state = RabbitState.Exit;
m_exitTime = 0f;
m_animator.SetBool("exiting", true);
}
private void Update()
{
if (MiniGameManager.gameState == GameState.Play)
{
float dt = Time.deltaTime;
if (state == RabbitState.None)
{
body.SetActive(false);
m_resetTime -= dt;
if (m_resetTime <= 0)
Pop();
return;
}
else if (state == RabbitState.Idle)
{
m_exitTime += dt;
if (m_exitTime >= 2)
Exit();
return;
}
}
else
return;
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 15558cb121c5e014abd8b42b3ff2bc1c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SetGamePanel : MonoBehaviour
{
static public SetGamePanel Instance;
private Animator m_animator;
private Image m_image;
public GameObject backPanel;
private void Awake()
{
Instance = this;
}
private void Start()
{
m_image = GetComponent<Image>();
m_animator = GetComponent<Animator>();
m_animator.SetTrigger("Play");
}
public void SetPanelOn()
{
backPanel.SetActive(true);
}
public void SetPanelOff()
{
m_image = null;
backPanel.SetActive(false);
MiniGameManager.gameState = GameState.Play;
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 039d8d6c72f18ea4b8a81ac8f84505b2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class SetMiniGame : MonoBehaviour
{
static public SetMiniGame Instance;
public GameObject UIButton;
public Image backPanel;
private Color m_color;
private float fadeTime = 1f;
float start;
float end;
float time = 0f;
private void Awake()
{
Instance = this;
}
public void SetButton(bool open)
{
UIButton.SetActive(open);
}
public void StartMiniGameScene()
{
StartCoroutine(ImageFadeOut());
}
protected IEnumerator ImageFadeOut()
{
m_color.a = 0f;
m_color = backPanel.color;
start = 0f; end = 1f; time = 0f;
backPanel.gameObject.SetActive(true);
while (m_color.a < 1f)
{
time += Time.deltaTime / fadeTime;
m_color.a = Mathf.Lerp(start, end, time);
backPanel.color = m_color;
yield return null;
}
SceneManager.LoadScene("MiniGameScene");
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: c27048ecc90a1a64fbc55f0d3409c3e5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: