159 lines
3.7 KiB
C#
159 lines
3.7 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 newBuildingUI;
|
|
public GameObject buildingLevelupUI;
|
|
public GameObject backButton;
|
|
public UnitCtrl[] units;
|
|
public TMP_Text buyText;
|
|
public TMP_Text sellText;
|
|
public TMP_Text moneyText;
|
|
public Image[] unitSpriteButton;
|
|
public TMP_Text[] unitTextButton;
|
|
|
|
public SummonsUnit player;
|
|
public SummonsUnit enemy;
|
|
public BuildingCtrl buildingCtrl;
|
|
public bool isEndGame;
|
|
private float delay;
|
|
|
|
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;
|
|
delay = 0.0f;
|
|
for(int n = 0; n < unitSpriteButton.Length; n++)
|
|
{
|
|
unitSpriteButton[n].sprite = units[n].unitSprite;
|
|
unitTextButton[n].text = units[n].unit.buy[0].ToString();
|
|
}
|
|
//테스트용 일단은 이곳에서 임시 처리
|
|
Statics.chapter = 101;
|
|
uiExit();
|
|
}
|
|
|
|
public void MoveCamera(float move)
|
|
{
|
|
this.move = move;
|
|
}
|
|
|
|
public void CtrlButton()
|
|
{
|
|
anim.SetTrigger("MoveUI");
|
|
}
|
|
private void Update()
|
|
{
|
|
if (isEndGame)
|
|
{
|
|
delay += Time.deltaTime;
|
|
if(delay > 3.0f)
|
|
{
|
|
//게임씬으로 이동
|
|
GameManager.Instance.NextScene(GameManager.eScene.Game);
|
|
}
|
|
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++;
|
|
enemy.EnemyStageSet(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], units[count].unitSprite);
|
|
uiExit();
|
|
}
|
|
|
|
public void DeleteBuilding()
|
|
{
|
|
buildingCtrl.DeletBuilding();
|
|
uiExit();
|
|
}
|
|
|
|
public void LevelUpBuilding()
|
|
{
|
|
buildingCtrl.LevelUp();
|
|
uiExit();
|
|
}
|
|
|
|
public void LevelupBuyAndSellText(int buy, int sell)
|
|
{
|
|
buyText.text = $"강화({buy})";
|
|
sellText.text = $"건물 제거({sell})";
|
|
}
|
|
|
|
public void TextUpdate(int addMoney)
|
|
{
|
|
if (money != int.Parse(moneyText.text))
|
|
Debug.LogError("버그발견");
|
|
money += addMoney;
|
|
if(money < 0)
|
|
money = 0;
|
|
else if(money > 999999)
|
|
money = 999999;
|
|
moneyText.text = money.ToString();
|
|
}
|
|
|
|
public void OnSetting()
|
|
{
|
|
SettingWindws.Instance.SetUI(false);
|
|
}
|
|
} |