Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class HitEffect : MonoBehaviour
- {
- MaterialPropertyBlock props;
- Renderer[] renderers;
- //Animator anim; uncomment if you have an animator attached and a hit animation
- // Start is called before the first frame update
- void Start()
- {
- props = new MaterialPropertyBlock();
- renderers = transform.GetComponentsInChildren<Renderer>();
- // anim = GetComponent<Animator>(); uncomment if you have an animator attached and a hit animation
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.H))
- {
- // anim.Play("Hit"); uncomment if you have an animator attached and a hit animation
- StartCoroutine(HitShaderEffect());
- }
- }
- IEnumerator HitShaderEffect()
- {
- props.SetFloat("_Hit", 1f);
- for (int i = 0; i < renderers.Length; i++)
- {
- renderers[i].SetPropertyBlock(props);
- }
- yield return new WaitForSeconds(0.1f);
- props.SetFloat("_Hit", 0f);
- for (int i = 0; i < renderers.Length; i++)
- {
- renderers[i].SetPropertyBlock(props);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement