SFE_matAlphaInOut.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. var alphaIn:float=2;
  2. var alphaStay:float=1;
  3. var alphaOut:float=3;
  4. var otherColors:float=0.5;
  5. private var time:float=0;
  6. private var alpha:float=0;
  7. var killObjectOnEnd:boolean=true;
  8. function Start () {
  9. if (alphaIn<=0) //debug hack...
  10. {
  11. alphaIn=0.1;
  12. Debug.Log("Please don't set AlphaIn to zero or below...(matAlphaInOut script)");
  13. }
  14. if (alphaOut<=0) //debug hack...
  15. {
  16. alphaOut=0.1;
  17. Debug.Log("Please don't set AlphaOut to zero or below...(matAlphaInOut script)");
  18. }
  19. renderer.material.SetColor("_TintColor", Color(otherColors, otherColors, otherColors ,alpha));
  20. }
  21. function Update () {
  22. time+=Time.deltaTime;
  23. if (time<alphaIn) //fading in
  24. {
  25. alpha=time/alphaIn;
  26. }
  27. if (time>=alphaIn && time<(alphaIn+alphaStay)) //staying
  28. {
  29. alpha=1;
  30. }
  31. if (time>=alphaIn+alphaStay && time<(alphaIn+alphaStay+alphaOut)) //fading out
  32. {
  33. alpha=1-((time-(alphaIn+alphaStay))/alphaOut);
  34. }
  35. renderer.material.SetColor("_TintColor", Color(otherColors, otherColors, otherColors ,alpha));
  36. if (time>=(alphaIn+alphaStay+alphaOut) && killObjectOnEnd==true)
  37. {
  38. Destroy(gameObject);
  39. //Debug.Log("Destroyed.,,");
  40. }
  41. }