| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace DamageNumbersPro.Demo
- {
- public class DNP_Target : MonoBehaviour
- {
- public Vector3 movementOffset = new Vector3(0, 0, 0);
- Material mat;
- float defaultBrightness;
- Coroutine hitRoutine;
- Coroutine flipRoutine;
- bool flipping;
- Vector3 originalPosition;
- void Start()
- {
- mat = GetComponent<MeshRenderer>().material;
- defaultBrightness = mat.GetFloat("_Brightness");
- flipping = false;
- originalPosition = transform.position;
- }
- void Update()
- {
- // Move around
- transform.position = originalPosition + movementOffset * Mathf.Sin(Time.time);
- }
- public void Hit()
- {
- if(hitRoutine != null)
- {
- StopCoroutine(hitRoutine);
- }
- hitRoutine = StartCoroutine(HitCoroutine());
- if (!flipping)
- {
- if (flipRoutine != null)
- {
- StopCoroutine(flipRoutine);
- }
- flipRoutine = StartCoroutine(FlipCoroutine());
- }
- }
- IEnumerator HitCoroutine()
- {
- float brightness = 1f;
- while( brightness < 3f)
- {
- // Glow up
- brightness = Mathf.Min(3, Mathf.Lerp(brightness, 3 + 0.1f, Time.deltaTime * 20f));
- mat.SetFloat("_Brightness", brightness);
- yield return null;
- }
- while(brightness > defaultBrightness)
- {
- // Glow down
- brightness = Mathf.Max(defaultBrightness, Mathf.Lerp(brightness, defaultBrightness - 0.1f, Time.deltaTime * 10f));
- mat.SetFloat("_Brightness", brightness);
- yield return null;
- }
- }
- IEnumerator FlipCoroutine()
- {
- flipping = true;
- float angle = 0f;
- while(angle < 180f)
- {
- angle = Mathf.Min(180, Mathf.Lerp(angle, 190f, Time.deltaTime * 7f));
- transform.eulerAngles = new Vector3(angle, 0, 0);
- yield return null;
- if(angle > 150f)
- {
- flipping = false;
- }
- }
- }
- }
- }
|