so i want to get fade out effect before my “object” die, but when i try it the object just wait and poof destroyed in an instant… is there anything wrong with my code?
var atk : float = 0;
var def : float = 0;
var mgc : float = 0;
var hp : float = 100;
var maxhp : float = 100;
function Start () {
}
function Update () {
if(Input.GetKeyDown("a")){
hp-=11;
Debug.Log("Your Hp now is"+hp);
}
if(hp>maxhp){
hp=maxhp;
}
else if(hp<=0){
hp=0;
iTween.FadeTo(gameObject, {"alpha":0,"time":2, "onComplete":"destroy"});
}
}
function destroy():void{
Destroy(gameObject);
}
if it’s about the object, i try to use cube that have Diffuse shader with jpeg material… maybe that’s the problem?
Does the shader you are using for your object support transparency and have a main color?
– robertbuhow to say about this, i dont understand.. emm, my shader is Diffuse, and i use jpg image as the material to this object.. how to tell if it support transparency or not?
– RgalaxyThe standard Diffuse shader does not support transparency. Change the shader on your material to Transparent/Diffuse. You can test if a shader supports diffuse in the editor by changing the alpha of the main color of that shader in the editor.
– robertbuok, i've tried it, its working greatly, but there's some problem, my object cannot cast any shadow anymore.. is there any way to achieve this? i mean, after i change it to transparent diffuse, the object's shadow is gone too :(
– RgalaxyI don't know. You'll have to thrash around and find the right shader. Doing a quick search on "Diffuse Transparent Shadow" yielded this link that might be what you are looking for: [http://answers.unity3d.com/questions/285847/transparency-shader-that-allows-shadows.html][1] [1]: http://answers.unity3d.com/questions/285847/transparency-shader-that-allows-shadows.html
– robertbu