|
In first person shooter games like Call of Duty and others, whenever you're hurt you get a little blood-like splat on your screen and that slowly becomes transparent. Is there any simple way to do this? Or would I have to create every single image?
(comments are locked)
|
|
I answered a similar question some time ago: http://answers.unity3d.com/questions/189677/blood-damage-like-call-of-duty.html Thanks! Based upon what I read I tried to make what I wanted. (Basically have a method that's called and it sets the image fully visable and it slowly becomes transparent. Rather than having blood all the time) So I tried this and nothings happening. (Btw, I can't figure out how to put all my code into the code box thingy) var hurt : GUITexture; private var alpha = 100; function Start () { var r = Rect(-Screen.width/2, -Screen.height/2, Screen.width, Screen.height); hurt.pixelInset = r; } function Update () { if (alpha > 0) alpha--; } function Hurt() { alpha = 100; }
Apr 03 '12 at 12:02 AM
iguana72
Hey there, You're on the right track. The code you have there works, however because you are subtracting one integer value per frame (because you are dynamically typecasting, the compiler assumes alpha is an int), its jumping straight from fully opaque to fully transparent in one frame, which isn't what you want. I instead used Time.deltaTime and a speed multiplier to smooth the fade (I would use Lerp, but to be honest, I've never fully understood how to get them to work properly, because the docs are wrong ...) Here's code in which your texture immediately begins to fade: If you want some help getting it to fade after a certain amount of time has elapsed, just ask :) Hope that helps, Klep P.S. If you want to format code in comments properly, highlight the whole code in the answer box, press the 101010 button, then copy newly formatted code into your comment and your good to go :) Sometimes it can be a bit touch and go though ...
Apr 03 '12 at 03:48 AM
Kleptomaniac
Thanks Klepto. I tried putting your code in place of mine, but nothing shows up. I added a debug to make sure the Hurt method (Which I added) was actually called. By the way, I'm no entirely sure what value I should set alpha to to make it visible. That may be the problem.
Apr 03 '12 at 04:02 AM
iguana72
To make it entirely visible? The alpha of a material or texture is based on a range from 0 to 1 (0 being fully transparent, 1 being fully opaque), so to make your texture fully opaque you would set its alpha value to 1. :) So, I'm assuming that your Hurt() function is called when you are shot? Is the debug you added being called? Make sure in that function that alpha is being set to 1 as opposed to 100 (however even with a value of 100 the texture should still show up). Hmm ...
Apr 03 '12 at 04:21 AM
Kleptomaniac
I have tested everything in my code and it all works fine, so perhaps showing me how you've inputted it into your own code would help?
Apr 03 '12 at 04:22 AM
Kleptomaniac
(comments are locked)
|
|
Use a script or Animation Editor to run the alpha on the main color of the material it uses from 1 to 0. Thanks. But that's not really going to work. The script I use to place the image on the screen uses a texture. How can I place a material on the center of the screen? Here's the code I tried using.
Apr 02 '12 at 11:23 PM
iguana72
(comments are locked)
|
