123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- 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>();
- 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<SwipeMove>();
- //Destination();
- Agent.enabled = false;
- NotificationCenter.AddListener(OnGameStart, NotificationType.GameStart);
- NotificationCenter.AddListener(OnGameOver, NotificationType.GameOver);
- StartPos = transform.position;
- Rig = GetComponent<Rigidbody>();
-
- }
- 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);
- }
- }
|