using System.Collections; using System.Collections.Generic; using UnityEngine; public class SkinlessMonsterAnimator : MonoBehaviour { [SerializeField] private Animator animator; [SerializeField] [Tooltip("This is the object with the skin dissolve material")] private GameObject modelObject; [SerializeField] private List objectsThatFallOnDeath = new(); [SerializeField] private float deathSpeed = 5f; [SerializeField] private float fastDeathduration = 1f; [SerializeField] private float deathDuration = 5f; private float curDeathSpeed = 5f; private Material dissolveMaterial; private bool isAlive = true; private float speed; public bool IsRunning { get; private set; } // Start is called before the first frame update private void Start() { dissolveMaterial = modelObject.GetComponent().materials[0]; curDeathSpeed = deathSpeed; } // Update is called once per frame private void Update() { if (isAlive) { animator.SetFloat("Speed", speed); } else { var quantity = dissolveMaterial.GetFloat("_DissolveQuantity"); quantity = Mathf.Lerp(quantity, -2, Time.deltaTime * curDeathSpeed); dissolveMaterial.SetFloat("_DissolveQuantity", quantity); } } public void StartMoving() { if (isAlive) { IsRunning = true; speed = 1; } } public void StopMoving() { if (isAlive) { speed = 0; IsRunning = false; } } public void Attack() { if (isAlive) animator.SetTrigger("Attack"); } /// /// 0,1,2,3 /// /// public void SetAttackType(int attackType) { animator.SetInteger("AttackIndex", attackType); } public void InLight() { if (isAlive) animator.SetBool("InLight", true); } public void NotInLight() { if (isAlive) animator.SetBool("InLight", false); } public void AttackScream() { if (isAlive) animator.SetTrigger("AttackScream"); } public void Kill(bool fast = false) { //animator.speed = 0; InLight(); isAlive = false; foreach (var obj in objectsThatFallOnDeath) { obj.AddComponent(); if (obj.GetComponent() != null) obj.GetComponent().enabled = false; } var dur = deathDuration; if (fast) { dur = fastDeathduration; curDeathSpeed = deathSpeed * (deathDuration / fastDeathduration); } StartCoroutine(destroyAfterSeconds(dur)); } private IEnumerator destroyAfterSeconds(float duration) { yield return new WaitForSeconds(duration); Destroy(gameObject); } }