123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using DG.Tweening;
- using System;
- using UnityEngine.AI;
- public class PickUp : MonoBehaviour
- {
- public enum PickUpType
- {
- Baloon,
- Heart,
- Fall,
- Candy,
- Cristal,
- Jump,
- Rock
- }
- public PickUpType CurPickUpType;
- public Vector3 SatrtPosition;
- public Quaternion SatrtRotation;
- private Transform StartParent;
- void Awake()
- {
- SatrtPosition = transform.position;
- SatrtRotation = transform.rotation;
- StartParent = transform.parent;
- }
- public void ResetPickUp()
- {
- transform.position = SatrtPosition;
- transform.SetParent(StartParent);
- transform.gameObject.SetActive(true);
- transform.localScale = Vector3.one;
- transform.rotation = SatrtRotation;
- transform.GetComponent<Collider>().enabled = true;
- }
- private void OnTriggerEnter(Collider other)
- {
- //Debug.Log(other.tag);
- if (other.tag == "Player")
- {
- switch(CurPickUpType)
- {
- case PickUpType.Baloon:
- Debug.Log("Baloon");
- other.GetComponent<RunnersController>().FlyPlayer();
- other.GetComponent<RunnersController>().Agent.speed *= 1.3f;
- GetComponent<Collider>().enabled = false;
- transform.SetParent(other.transform);
- transform.localPosition = Vector3.zero + Vector3.up*2;
- StartCoroutine(FlyWithBaloon(other));
- //gameObject.SetActive(false);
- break;
- case PickUpType.Heart:
- if(other.GetComponent<RunnersController>().IsPlayer)
- {
- Core.Instance.SetHeart();
- }
-
- UIManager.Instance.UpdateGameplayMenu();
- transform.DOScale(0, 0.5f);
- transform.DOLocalMove(transform.localPosition + Vector3.up*2, 0.5f).OnComplete(() => {
- transform.DOScale(0, 0.5f).OnComplete(() => {
- gameObject.SetActive(false);
- });
- });
- break;
- case PickUpType.Cristal:
- Core.Instance.SetCristal();
- UIManager.Instance.UpdateGameplayMenu();
- transform.DOScale(0, 0.5f);
- transform.DOLocalRotate(transform.rotation * Vector3.up, 2);
- transform.DOLocalMove(transform.localPosition + Vector3.up * 3, 1f).OnComplete(() => {
- transform.DOScale(0, 1f).OnComplete(() => {
- gameObject.SetActive(false);
- });
- });
- break;
- case PickUpType.Candy:
- //other.GetComponent<RunnersController>().FlyPlayer();
- other.GetComponent<RunnersController>().Agent.speed*= 1.3f;
- transform.DOScale(0, 0.5f);
- transform.DOLocalMove(transform.localPosition + Vector3.up*2, 0.5f).OnComplete(() => {
- transform.DOScale(0, 0.5f).OnComplete(() => {
- gameObject.SetActive(false);
- });
- });
- break;
- case PickUpType.Fall:
- other.GetComponent<RunnersController>().FallPlayer();
- other.GetComponent<RunnersController>().enabled = false;
- other.GetComponent<SwipeMove>().enabled = false;
- other.GetComponent<NavMeshAgent>().enabled = false;
- other.GetComponent<Collider>().enabled = false;
- //transform.DOScale(0, 0.5f);
- //transform.DOLocalMove(transform.localPosition + Vector3.up * 2, 0.5f).OnComplete(() => {
- // transform.DOScale(0, 0.5f).OnComplete(() => {
- // gameObject.SetActive(false);
- // });
- //});
- break;
- case PickUpType.Rock:
- other.GetComponent<RunnersController>().Agent.speed *= 0.7f;
- other.GetComponent<RunnersController>().Stumble();
- //other.GetComponent<RunnersController>().enabled = false;
- //other.GetComponent<SwipeMove>().enabled = false;
- //other.GetComponent<NavMeshAgent>().enabled = false;
- //other.GetComponent<Collider>().enabled = false;
- break;
- }
- }
- }
- private IEnumerator FlyWithBaloon(Collider other)
- {
- other.GetComponent<NavMeshAgent>().baseOffset = 2;
- yield return new WaitForSeconds(3);
- transform.DOScale(0, 0.5f);
- other.GetComponent<NavMeshAgent>().baseOffset = 0;
- }
- public void Update()
- {
- switch(CurPickUpType)
- {
- case PickUpType.Baloon:
- //transform.DOLocalMoveY(Vector3.forward, -80 * Time.deltaTime);
- break;
- case PickUpType.Heart:
- transform.Rotate(Vector3.forward, -100 * Time.deltaTime);
- break;
- case PickUpType.Fall:
- //transform.Rotate(Vector3.forward, -100 * Time.deltaTime);
- break;
- case PickUpType.Candy:
- transform.Rotate(Vector3.forward, -100 * Time.deltaTime);
- break;
- case PickUpType.Jump:
- //transform.Rotate(Vector3.forward, -100 * Time.deltaTime);
- break;
- case PickUpType.Cristal:
- transform.Rotate(Vector3.forward, -100 * Time.deltaTime);
- break;
- }
- }
- }
|