123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Sirenix.OdinInspector;
- using KairoEngine.Core;
- using KairoEngine.Utilities;
- namespace KairoEngine.CharacterSystem
- {
- public class RemoveBody : MonoBehaviour
- {
- public float waitTime = 30f;
- public float animTime = 3f;
- private CharacterController character;
- private bool removing = false;
- private bool isAnimating = false;
- private Vector3 startPosition;
- private Vector3 endPosition;
- private float counter = 0f;
- void Start()
- {
- character = GetComponent<CharacterController>();
- if(character == null) Debug.LogError("Could not find a CharacterController component.", this.gameObject);
- }
- void Update()
- {
- if(character == null) return;
- if(character.IsDead() && !removing) StartTimer();
- if(isAnimating) Animate();
- }
- void StartTimer()
- {
- removing = true;
- character.puppetMaster.gameObject.SetActive(false);
- StartCoroutine(Timer.Start(waitTime, false, () =>
- {
- startPosition = transform.position;
- endPosition = startPosition;
- endPosition.y -= 1f;
- isAnimating = true;
- character.RemoveColliders();
- }));
- }
- void Animate()
- {
- counter += Time.deltaTime;
- Vector3 pos = startPosition;
- float y = Mathf.Lerp(startPosition.y, endPosition.y, counter/animTime);
- pos.y = y;
- transform.position = pos;
- if(counter > animTime)
- {
- isAnimating = false;
- RemoveCharacter();
- }
- }
- void RemoveCharacter()
- {
- Destroy(character.transform.root.gameObject);
- }
- }
- }
|