所以我知道我不是唯一一个,我发现的大多数例子都太复杂或充满了JavaScript语法废话。
我希望这有助于其他人!
答案 0 :(得分:0)
这就是我所做的。我首先创建了一个非常简单的自定义着色器。此示例来自http://wiki.unity3d.com/index.php?title=Blend_2_Textures:
Shader "TextureChange" {
Properties {
_Blend ("Blend", Range (0, 1) ) = 0.5
_MainTex ("Texture 1", 2D) = ""
_Texture2 ("Texture 2", 2D) = ""
}
SubShader {
Pass {
SetTexture[_MainTex]
SetTexture[_Texture2] {
ConstantColor (0,0,0, [_Blend])
Combine texture Lerp(constant) previous
}
}
} }
然后,我只是添加了一个MonoScript来在两个纹理之间来回混合:
enum Direction {
up,
down
}
public class BlendObjectTextures : MonoBehaviour {
public float delay, step;
public bool blendTextures = true;
private Direction blendDirection;
private float blendAmount;
void Start () {
StartCoroutine(BlendTextures());
}
void Update () {
//only update display on every frame
renderer.material.SetFloat("_Blend", blendAmount);
}
IEnumerator BlendTextures () {
while (blendTextures) {
Debug.Log("Blend Amount - " + blendAmount);
yield return new WaitForSeconds(delay);
if (blendAmount <= 0) { //Blend from first into second texture
blendDirection = Direction.up; //The default
}
if (blendAmount >= 1) { //Blend from second into first texture
blendDirection = Direction.down;
}
if (blendDirection == Direction.up) {
blendAmount += step; //Increment blend into second texture
} else {
blendAmount -= step; //Decrement blend back into first texture
}
}
}
}
在Unity编辑器中,您可以指定延迟(默认值为零),混合的步长量以及完全关闭效果。我在使用Unity 4.6.2的项目中对此进行了测试,它运行正常。
就像我说的那样,我希望这是你在Unity项目中尝试做的好跳板!