Unity拖影效果

本文记录了在Unity游戏开发中创建技能拖影效果的过程,包括两个关键脚本的使用,实现了动态的拖影视觉效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在开发过程中遇到做一个技能需要带拖影效果,参考别人的资料写了一个拖影效果,记录一下以备使用。一共两个脚本,但只需要挂载EffectMotionGhost即可,代码内容如下所示

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

/// <summary>
/// 运动残影效果
/// </summary>
public class EffectMotionGhost : MonoBehaviour {
	//残影生成间隔
	public float m_createDuration = 0.2f;
	//残影生命周期
	public float m_lifeCycle = 0.4f;
	//上一次组合时间
	private float m_lastCombinedTime = 0.0f;
	//残影颜色
	public Color m_ghostColor = new Color(0.54f,0.17f,0.88f);
	//是否使用原模型特性
	public bool m_isUseModelDefault = false;
	//需要剔除的渲染网格
	public MeshFilter[] m_exceptRenderMeshFilters;
	//存贮对象包含的MeshFilter组件
	private MeshFilter[] m_meshFilters;
	//存贮对象包含的MeshRenderer组件
	private MeshRenderer[] m_meshRenders;
	//存贮对象包含的m_skinnedMeshRenderers组件
	private SkinnedMeshRenderer[] m_skinnedMeshRenderers;
	//存储残影
	private List<EffectMotionGhostData> m_ghostList = new List<EffectMotionGhostData>();
	private List<EffectMotionGhostData> m_deleteGhostList = new List<EffectMotionGhostData>();
	private Object m_ghostMaterial;
	void Start() {
		m_meshFilters = gameObject.GetComponentsInChildren<MeshFilter>();
		//获取蒙皮网格
		m_skinnedMeshRenderers = gameObject.GetComponentsInChildren<SkinnedMeshRenderer>();

		m_ghostMaterial = Resources.Load("EffectMaterial/EffectMitionGhostMaterial");
	}

	void OnDisable() {
		//消灭所有残影
		for(int i = 0;i < m_ghostList.Count;i++){
			DestroyImmediate(m_ghostList[i].m_gh
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值