1、模型呼吸方法
需要导入DoTween插件
//设置模型呼吸所用
private Color color;
private float alpha = 1;
private float time = 1.5f;
Tween tween;
// Start is called before the first frame update
/// <summary>
/// 模型呼吸的方法2
/// </summary>
public void ModelHuXiFunc(GameObject go)
{
Material material = go.GetComponent<MeshRenderer>().materials[0];
tween = DOTween.To(() => alpha = 1, x => alpha = x, 0.05f, time).OnUpdate(() =>
{
color.a = alpha;
color.r = material.color.r;
color.g = material.color.g;
color.b = material.color.b;
material.SetColor("_BaseColor", color);
}).SetLoops(-1, LoopType.Yoyo);
}
注意
在HDRP中是material.SetColor(“_BaseColor”, color);
在普通3D项目中为 material.SetColor(“_Color”, color);,这里怎么去区分呢,需要去找模型上的shader,看shader中的参数是什么,例如,找到模型去Edit shader,就可以知道需要去设置什么参数了。
2、测试
/*****************************************************************
*UnityVersion: 2020.3.1f1
*Function:
*******************************************************************/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Ceshi
{
/// <summary>
///
/// </summary>
public class ModelHuXiTestScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
this.GetComponent<ModelHuXiScript>().ModelHuXiFunc(this.gameObject);
}
// Update is called once per frame
void Update()
{
}
}
}
3、结果