using System; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.AI; using UnityEngine.UI; public class RunnersController : MonoBehaviour { [SerializeField] public NavMeshAgent Agent; [SerializeField] private int IDPlayer; [SerializeField] public Transform _target; public TextMeshPro NamePlayerText; public bool IsPlayer; public bool IsFly; //public bool IsJump; public bool IsSpeedUp; public GameObject BaloonObject; public SwipeMove SwipeMove; public Animator Anim; public Vector3 StartPos; private float TimerFly = 3; private float DefaultTimerFly = 3; private Rigidbody Rig; private float _gravity = 9.8f; public void SetTarget(Transform tr) { _target = tr; } public void SetPlayer(string text) { SwipeMove = GetComponent(); SwipeMove.enabled = true; UIManager.Instance.CompleteCameraController.Target = this.transform; NamePlayerText.text = text; NamePlayerText.gameObject.SetActive(true); //SwipeMove.enabled = true; } public void SetRollerAnim() { Anim.SetTrigger("SitRoller"); } public void Start() { Agent.enabled = true; SwipeMove = GetComponent(); //Destination(); Agent.enabled = false; NotificationCenter.AddListener(OnGameStart, NotificationType.GameStart); NotificationCenter.AddListener(OnGameOver, NotificationType.GameOver); StartPos = transform.position; Rig = GetComponent(); } public void SetFlyToTowerAnim() { Anim.SetBool("FlyInTower", true); } public void EnableFlyToTowerAnim() { Anim.SetBool("FlyInTower", false); } public void ResetPos() { transform.position = StartPos; } public void FlyPlayer() { TimerFly = DefaultTimerFly; Anim.SetBool("Move", false); Anim.SetBool("Fly", true); IsFly = true; } public void Idle() { Anim.SetBool("Move", false); Anim.SetBool("Fly", false); Anim.SetBool("Kiss", false); Anim.SetBool("Fall", false); } public void Move() { //IsFly = true; //IsMove = false; //IsKiss = false; //IsJump = false; if(Core.Instance.IsGameMode != Core.StateModeGame.Kiss) { Anim.SetBool("Kiss", false); Anim.SetBool("Move", true); Anim.SetBool("Fly", false); Anim.SetBool("Fall", false); } else { Anim.SetBool("Kiss", true); Anim.SetBool("Move", false); Anim.SetBool("Fly", false); Anim.SetBool("Fall", false); } } public void Kiss() { //IsFly = true; //IsMove = false; //IsKiss = false; //IsJump = false; Anim.SetBool("Move", false); Anim.SetBool("Fly", false); Anim.SetBool("Kiss", true); Anim.SetBool("Fall", false); //Anim.PlayInFixedTime("Kiss", 1, 2f); } public void FallPlayer() { Anim.SetBool("Move", false); Anim.SetBool("Fly", false); Anim.SetBool("Kiss", false); Anim.SetBool("Fall", true); Agent.speed = 0; } private void OnGameOver(Notification note) { //throw new NotImplementedException(); } private void OnDestroy() { NotificationCenter.RemoveListener(OnGameStart, NotificationType.GameStart); NotificationCenter.RemoveListener(OnGameOver, NotificationType.GameOver); } public void Stumble() { Anim.SetTrigger("Stumble"); } private void OnGameStart(Notification note) { Agent.enabled = true; Anim.SetBool("Move", true); Destination(); } public void Destination() { if (Agent.enabled) { try { Agent.destination = _target.position; } catch { } } } private void Update() { if(Core.Instance.LevelEnd) { Idle(); return; } if(Anim.GetBool("Fall")) { Agent.enabled = false; transform.Translate(transform.up * -_gravity * Time.deltaTime); return; } if(IsFly) { TimerFly -= Time.deltaTime; if(TimerFly <= 0) { //TimerFly = DefaultTimerFly; IsFly = false; Move(); } } if(Core.Instance.IsGameMode == Core.StateModeGame.IsGameMode) { //switch(SwipeMove.DirSwipe) // { // case SwipeMove.DirectionSwipe.Left: // Anim.SetFloat("Blend", Mathf.Lerp(Anim.GetFloat("Blend"), 0, 10 * Time.deltaTime)); // break; // case SwipeMove.DirectionSwipe.Right: // Anim.SetFloat("Blend", Mathf.Lerp(Anim.GetFloat("Blend"), 1, 10 * Time.deltaTime)); // break; // } Anim.SetFloat("Blend", Mathf.Lerp(Anim.GetFloat("Blend"), 0.5f, 1 * Time.deltaTime)); //if (Vector3.Dot(vel, transform.right) > 0.01f) //{ //} //else if (Vector3.Dot(vel, transform.right) < 0.01f) //{ // Anim.SetFloat("Blend", Mathf.Lerp(Anim.GetFloat("Blend"), 0, 10 * Time.deltaTime)); //} //else { Anim.SetFloat("Blend", 0.5f); } if(Agent) { Agent.SetDestination(_target.position); Agent.autoTraverseOffMeshLink = true; } } else { Agent.autoTraverseOffMeshLink = false; } } public void ResetAnimation() { ResetAllAnimation(); Destination(); } public void ResetAllAnimation() { Anim.SetBool("Move", false); Anim.SetBool("Fly", false); Anim.SetBool("Kiss", false); Anim.SetBool("Fall", false); Anim.SetBool("FlyInTower", false); } }