using UnityEngine;public class Enemy : MonoBehaviour {private SpriteRenderer render;public Sprite[] spriteHit;public float hitTimer = 0.2f;private float resetHitTime;void Start () {render = GetComponent<SpriteRenderer>();resetHitTime = hitTimer;//以后resetHitTime一直等于0.2fhitTimer = 0;}void Update(){if (hitTimer > 0){hitTimer -= Time.deltaTime;int frameIndex = (int)((resetHitTime - hitTimer) / (1f / explosionAnimationFrame));frameIndex = frameIndex % 2;render.sprite = spriteHit[frameIndex];}}public void BeHit(){hitTimer = resetHitTime;}}
如果觉得《unity中物体受伤时切换受伤图片》对你有帮助,请点赞、收藏,并留下你的观点哦!