64 lines
1.8 KiB
C#
64 lines
1.8 KiB
C#
|
|
using System.Collections;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
using DG.Tweening;
|
|
public class GameCanvas : MonoBehaviour
|
|
{
|
|
public static GameCanvas instance;
|
|
void Awake()
|
|
{
|
|
instance = this;
|
|
}
|
|
|
|
public EventTrigger gameInputPanel;
|
|
|
|
public Image turnTimerSliderTransform;
|
|
public Color redColor = Color.red;
|
|
public Color blueColor = Color.blue;
|
|
public TMP_Text txtWhosTurn;
|
|
public TMP_Text txtTurnTimer;
|
|
public Image turnTimerRound;
|
|
|
|
|
|
|
|
void Update(){
|
|
UpdateTurnTimer();
|
|
}
|
|
Team prevTeam = Team.Red;
|
|
|
|
bool init=false;
|
|
void UpdateTurnTimer(){
|
|
if(NetPlayer.localPlayer == null){return;}
|
|
if(!init){
|
|
init=true;
|
|
SwitchTeams();
|
|
}
|
|
|
|
float turnTimerFillAmount = 1 - (GameManager.instance.turnTimerCounter / GameManager.instance.turnTimer);
|
|
if(prevTeam != GameManager.instance.SelectedTeam){
|
|
SwitchTeams();
|
|
prevTeam = GameManager.instance.SelectedTeam;
|
|
}
|
|
|
|
turnTimerSliderTransform.transform.localScale = new Vector3(turnTimerFillAmount, 1, 1);
|
|
txtTurnTimer.text = (GameManager.instance.turnTimer - GameManager.instance.turnTimerCounter).ToString("F0");
|
|
turnTimerRound.fillAmount = turnTimerFillAmount;
|
|
}
|
|
|
|
void SwitchTeams(){
|
|
bool isMyTurn = GameManager.instance.SelectedTeam == NetPlayer.localPlayer.myTeam;
|
|
|
|
Color newColor = GameManager.instance.SelectedTeam == Team.Red ? redColor : blueColor;
|
|
turnTimerSliderTransform.DOColor(newColor, 0.5f);
|
|
|
|
txtWhosTurn.DOFade(0, 0.25f).OnComplete(() => {
|
|
txtWhosTurn.text = isMyTurn ? "Your Turn" : "Opponent's Turn";
|
|
txtWhosTurn.DOFade(1, 0.25f);
|
|
});
|
|
}
|
|
|
|
}
|