135 lines
3.0 KiB
C#
135 lines
3.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class PlayCtrl : SingletonMonoBehaviour<PlayCtrl>
|
|
{
|
|
public GameObject camera;
|
|
public float speed;
|
|
float move = 0;
|
|
|
|
public Slider slider;
|
|
float summons;
|
|
int stage;
|
|
|
|
public Animator anim;
|
|
|
|
public GameObject unit;
|
|
|
|
public GameObject newBuildingUI;
|
|
public GameObject buildingLevelupUI;
|
|
public GameObject backButton;
|
|
public UnitCtrl[] units;
|
|
public Sprite[] unitImages;
|
|
public TMP_Text moneyText;
|
|
|
|
public SummonsUnit player;
|
|
public SummonsUnit enemy;
|
|
public BuildingCtrl buildingCtrl;
|
|
public bool isEndGame;
|
|
|
|
public int money;
|
|
|
|
//선택된 ui의 정보를 저장할 수 있게 만들기.
|
|
//레벨업 ui만들기
|
|
//backbutton을 누르면 둘다 꺼지게 만들기.
|
|
|
|
protected override void OnAwake()
|
|
{
|
|
summons = 0.1f;
|
|
slider.value = 0;
|
|
stage = 0;
|
|
money = 0;
|
|
moneyText.text = money.ToString();
|
|
isEndGame = false;
|
|
uiExit();
|
|
}
|
|
|
|
public void MoveCamera(float move)
|
|
{
|
|
this.move = move;
|
|
}
|
|
|
|
public void CtrlButton()
|
|
{
|
|
anim.SetTrigger("MoveUI");
|
|
}
|
|
private void Update()
|
|
{
|
|
if (isEndGame)
|
|
{
|
|
Debug.Log("게임종료");
|
|
return;
|
|
}
|
|
float deltaTime = Time.deltaTime;
|
|
camera.transform.position += Vector3.left * speed * deltaTime * move;
|
|
if (camera.transform.position.x < -40)
|
|
{
|
|
camera.transform.position = new Vector3(-40, 0, -10);
|
|
}
|
|
if (camera.transform.position.x > 40)
|
|
{
|
|
camera.transform.position = new Vector3(40, 0, -10);
|
|
}
|
|
slider.value += Time.deltaTime / 30;
|
|
if (slider.value >= 1)
|
|
{
|
|
slider.value -= 1;
|
|
summons = 0.1f;
|
|
stage++;
|
|
}
|
|
if (summons < slider.value)
|
|
{
|
|
int count = (int)(summons / 0.2);
|
|
player.Summons(count);
|
|
enemy.Summons(count);
|
|
summons += 0.2f;
|
|
}
|
|
|
|
}
|
|
|
|
public void uiExit()
|
|
{
|
|
newBuildingUI.SetActive(false);
|
|
buildingLevelupUI.SetActive(false);
|
|
backButton.SetActive(false);
|
|
buildingCtrl = null;
|
|
}
|
|
|
|
public void SelectUnit(int count)
|
|
{
|
|
buildingCtrl.NewBuilding(units[count], unitImages[count]);
|
|
uiExit();
|
|
}
|
|
|
|
public void DeleteBuilding()
|
|
{
|
|
buildingCtrl.DeletBuilding();
|
|
uiExit();
|
|
}
|
|
|
|
public void LevelUpBuilding()
|
|
{
|
|
buildingCtrl.LevelUp();
|
|
uiExit();
|
|
}
|
|
|
|
public void TextUpdate(int addMoney)
|
|
{
|
|
if (money != int.Parse(moneyText.text))
|
|
Debug.LogError("버그발견");
|
|
money += addMoney;
|
|
if(money < 0 || money > 999900)
|
|
Debug.LogError("가격버그발견");
|
|
moneyText.text = money.ToString();
|
|
}
|
|
}
|
|
/*
|
|
필요 작업사항
|
|
1. 유닛 생성 자원
|
|
2. 강화 조건 정하기
|
|
3. 건물 철거 반환자원 조건 정하기
|
|
4. UI적용
|
|
*/ |