OK I'm trying to create a cool death effect for my "Alien Zombie". I'm using the Dissolve shader from the Wiki:
// simple "dissolving" shader by genericuser (radware.wordpress.com)
// clips materials, using an image as guidance.
// use clouds or random noise as the slice guide for best results.
Shader "Custom Shaders/Dissolving" {
Properties {
_MainTex ("Texture (RGB)", 2D) = "white" {}
_SliceGuide ("Slice Guide (RGB)", 2D) = "white" {}
_SliceAmount ("Slice Amount", Range(0.0, 1.0)) = 0.5
}
SubShader {
Tags { "RenderType" = "Opaque" }
Cull Off
CGPROGRAM
//if you're not planning on using shadows, remove "addshadow" for better performance
#pragma surface surf Lambert addshadow
struct Input {
float2 uv_MainTex;
float2 uv_SliceGuide;
float _SliceAmount;
};
sampler2D _MainTex;
sampler2D _SliceGuide;
float _SliceAmount;
void surf (Input IN, inout SurfaceOutput o) {
clip(tex2D (_SliceGuide, IN.uv_SliceGuide).rgb - _SliceAmount);
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
}
ENDCG
}
Fallback "Diffuse"
}
I have it as a material on my "Alien Zombie" dead replacement... but it dissolves too quickly! Is there a way to slow the dissolve and delay it so it only dissolves a certain amount of time after the body has dropped to the ground?
And secondly how can I make it look sort of like the old TV series "The Invaders" when those alien died? And then destroy my dead alien body a short time after that?
I think on the destroy my dead alien I can just use a wait for seconds, but the rest I've got no clue how to do... has anyone done a cool effect like this and if so how did you do it?
EDIT here is where I keep trying to make my adjustment to slow the effect down but nothing happens?
Shader "Custom Shaders/Dissolving" {
Properties {
_MainTex ("Texture (RGB)", 2D) = "white" {}
_SliceGuide ("Slice Guide (RGB)", 2D) = "white" {}
_SliceAmount ("Slice Amount", Range(0.0, 1.0)) = 0.5
}
There is clearly some part to this I'm missing... Is there not a DETAILED tutorial on this stuff anywhere??
EDIT 03
I see sort of where I'm going wrong. I added a new script to my "Dead Replacement Alien Zombie":
function Start () {
// Use the Glossy shader on the material
renderer.material.shader = Shader.Find(" ZombieAlienDissolveMaterial");
}
function Update () {
// Dissolve
renderer.material.SetFloat( "_SliceAmount", 0.5 + Mathf.Sin(Time.time)*12 );
yield WaitForSeconds(12);
Destroy(gameObject);
}
But it STILL is doing Jack!?!
EDIT 04
Ok let's try again... I'm trying this and it's STILL NOT WORKING!!
function Start () {
// Use the Glossy shader on the material
renderer.material.shader = Shader.Find(" ZombieAlienDissolveMaterial");
}
function Update () {
// Dissolve
renderer.material.SetFloat( "_SliceAmount", 0.0 + Mathf.Sin(Time.time)*1 );
}
function KillSelf () {
yield WaitForSeconds(12);
Destroy(gameObject);
}
Like I say is there not a DETAILED tutorial on this anywhere, something step by step!
EDIT 05
I set up a new Zombie Alien Ragdoll prefab and gave it this script:
function Start () {
// Use the Glossy shader on the material
renderer.material.shader = Shader.Find("ZombieAlienDissolveMaterial");
}
function Update () {
// Dissolve
renderer.material.SetFloat( "_SliceAmount", 0.9 + Mathf.Sin(Time.time)*1 );
}
The Dissolve shader is attached to the "Body" of my Ragdoll (dead replacement) What hapens when I shoot my Alien Zombie is that his dead replacement shows up Bright Pink and the Dissolve material is NOT working.
I conducted a test where I just dragged into my scene a ragdoll with the Dissolve shader and the above attached script and when I play the game (test) in the inspector I can select my custom Dissolve Shader and it works, it dissolves in and out, I only want it to dissolve out but it also says it's a "Shader Instance??"
How do I fix this so that when I shoot my alien Zombies they're Dead Replacements/ragdolls Dissolve out?
I amended my answer with a link to what you need.
– flaviusxvii0.5 + Mathf.Sin(Time.time)*12 <-- This will produce values in the range -11.5 to 12.5.. you want 0 to 1. Also, you don't want to set the value once, wait 12 seconds, and then destroy the object. You won't see anything change that way. Why on Earth would you use 'yield' here?
– flaviusxvii** From the docs "Note that you can't use yield from within Update" http://unity3d.com/support/documentation/ScriptReference/index.Coroutines_26_Yield.html
– flaviusxviiI'm trying to use Yield because after it's done desolving I naturally want to remove my dead alien zombie from the scene. So how do I do that with what I have here?
– anon48034950Shader.Find(" ZombieAlienDissolveMaterial"); The leading space before "Zombie" might be an issue. If the compiler complaining? Are you getting any error messages? Have you chosen a good _SliceGuide? Your yield+Destroy would make more sense it it was at the end of your Start function.
– flaviusxvii