using System.Collections; using System.Collections.Generic; using UnityEngine; public class ChangeTransparent2D : MonoBehaviour { public int lives = 5; public float step = 0.15f; public string ignoreTag = ""; SpriteRenderer sp; float a = 1f; bool was = false; void Start() { sp = GetComponent(); } void OnTriggerEnter2D(Collider2D other) { if (other.tag == ignoreTag || was == true) { return; } lives--; if (lives <= 0) { Destroy(gameObject); } a -= 0.1f; sp.color = new Color(1, 1, 1, a); was = true; Invoke("Restart", 0.1f); } void Restart() { was = false; } }