Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by iguana72 · Apr 02, 2012 at 07:29 PM · guifpsimagefade

slowly make gui image more transparent

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Apr 02, 2012 at 09:26 PM

Use a script or Animation Editor to run the alpha on the main color of the material it uses from 1 to 0.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image iguana72 · Apr 02, 2012 at 11:23 PM 0
Share

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.

var texture : Texture2D;

var position : Rect; var show = false; function Start() { position = Rect( ( Screen.width - texture.width ) / 2, (Screen.height - texture.height ) / 2, texture.width, texture.height ); } function OnGUI() { if (show) GUI.DrawTexture( position, texture ); }
avatar image
0

Answer by aldonaletto · Apr 02, 2012 at 11:30 PM

I answered a similar question some time ago: http://answers.unity3d.com/questions/189677/blood-damage-like-call-of-duty.html

Comment
Add comment · Show 10 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image iguana72 · Apr 03, 2012 at 12:02 AM 0
Share

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--;

 hurt.color.a = $$anonymous$$athf.Clamp(alpha, 0, 1);

}

function Hurt() { alpha = 100; }

avatar image Kleptomaniac · Apr 03, 2012 at 03:48 AM 0
Share

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 ins$$anonymous$$d 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:

 var hurt : GUITexture;
 private var alpha : float = 1;
 private var decRate : float = 0.5;
 
 function Start () { 
 
     var r = Rect(-Screen.width/2, -Screen.height/2, Screen.width, Screen.height); 
     hurt.pixelInset = r;
      
 }
 
 function Update () {
 
     alpha -= Time.deltaTime * decRate;
     alpha = $$anonymous$$athf.$$anonymous$$ax(0, alpha);
     hurt.color.a = $$anonymous$$athf.Clamp01(alpha);
 
 }

If you want some help getting it to fade after a certain amount of time has elapsed, just ask :)

Hope that helps, $$anonymous$$lep

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 ...

avatar image iguana72 · Apr 03, 2012 at 04:02 AM 0
Share

Thanks $$anonymous$$lepto. I tried putting your code in place of $$anonymous$$e, 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.

avatar image Kleptomaniac · Apr 03, 2012 at 04:21 AM 0
Share

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 assu$$anonymous$$g that your Hurt() function is called when you are shot? Is the debug you added being called? $$anonymous$$ake 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 ...

avatar image Kleptomaniac · Apr 03, 2012 at 04:22 AM 0
Share

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?

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Fade GUITexture 1 Answer

FadeIn/FadeOut GUI Menu and Text 1 Answer

Repeat fade in and out 1 Answer

How can I move Text and Image component in unison inside of Canvas 0 Answers

How To Make Ammo & Realod for Gun & Spark for Gun ? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges