initial second level
This commit is contained in:
1 parent
be3defc280
commit
e51b34784c
18 files changed
+24668
-13
No files matched your search
@@ -0,0 +1,75 @@
|
||||
using Code.DI;
|
||||
using Code.Gameplay.Enemies;
|
||||
using Code.Gameplay.Player;
|
||||
using Code.Input;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using DG.Tweening;
|
||||
using Unity.VisualScripting;
|
||||
|
||||
namespace Code.UI
|
||||
{
|
||||
public class GameplayControllerSecond : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Image deathScreen;
|
||||
[SerializeField] private TMP_Text deathText;
|
||||
[SerializeField] private Button exitButton;
|
||||
[SerializeField] private PlayerHealth playerHealth;
|
||||
[SerializeField] private AudioSource audioSource;
|
||||
[SerializeField] private BoxCollider2D blockBorder;
|
||||
private IInputService _inputService;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_inputService = FindFirstObjectByType<DIContainer>().Resolve<IInputService>();
|
||||
_inputService.EnableMap(ActionMapping.Gameplay);
|
||||
|
||||
FindFirstObjectByType<PlayerMovement>().Construct(_inputService);
|
||||
|
||||
exitButton.onClick.AddListener(OnExitButtonPressed);
|
||||
playerHealth.OnDied += HandleDeath;
|
||||
|
||||
deathScreen.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void HandleDeath()
|
||||
{
|
||||
var clip = Resources.Load<AudioClip>("Audio/SFX/DeathSFX");
|
||||
audioSource.PlayOneShot(clip);
|
||||
_inputService.DisableMap(ActionMapping.Gameplay);
|
||||
deathScreen.gameObject.SetActive(true);
|
||||
|
||||
deathScreen.rectTransform.localScale = Vector3.zero;
|
||||
deathScreen.rectTransform.DOScale(1f, 0.3f)
|
||||
.SetEase(Ease.OutBack);
|
||||
|
||||
deathText.color = deathText.color.WithAlpha(0f);
|
||||
deathText.DOFade(1f, 0.6f)
|
||||
.OnComplete(() =>
|
||||
{
|
||||
deathText.DOFade(0.8f, 0.5f)
|
||||
.SetLoops(-1, LoopType.Yoyo)
|
||||
.SetEase(Ease.InOutSine);
|
||||
});
|
||||
}
|
||||
|
||||
private void OnExitButtonPressed()
|
||||
{
|
||||
DOTween.Kill(deathScreen.rectTransform);
|
||||
DOTween.Kill(deathText);
|
||||
|
||||
exitButton.onClick.RemoveAllListeners();
|
||||
SceneManager.LoadScene("MainMenu");
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!FindAnyObjectByType<BasicEnemy>())
|
||||
{
|
||||
blockBorder.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user