在触发消隐的物体(比如玩家)挂下面的代码,以及box collider,rigidbody 2d
using UnityEngine; public class ColliderFader : MonoBehaviour { ItemFader[] m_Faders; private void OnTriggerEnter2D(Collider2D collision) { m_Faders = collision.GetComponentsInChildren<ItemFader>(); foreach(ItemFader fader in m_Faders) { fader.FadeOut(); } } private void OnTriggerExit2D(Collider2D collision) { m_Faders = collision.GetComponentsInChildren<ItemFader>(); foreach (ItemFader fader in m_Faders) { fader.FadeIn(); } } }
再被消隐的物体上挂下面的脚本,以及box collider 2d trigger
using UnityEngine; using DG.Tweening; [RequireComponent(typeof(SpriteRenderer))] public class ItemFader : MonoBehaviour { SpriteRenderer render; private void Awake() { render = GetComponent<SpriteRenderer>(); } public void FadeOut() { Color color = new Color(1, 1, 1, Settings.fadeAlpha); render.DOColor(color, Settings.fadeDuration); } public void FadeIn() { Color color = new Color(1, 1, 1, 1); render.DOColor(color, Settings.fadeDuration); } }
标签:效果,render,color,消隐,2D,collision,Faders,void From: https://www.cnblogs.com/hankpeng123/p/16732938.html