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 Chris 30 · Apr 03, 2011 at 07:31 PM · damage

Make screen flash red on Damage

Hi

I want my screen to show red when player gets hit or damaged. I found some answers online but they didn't seem complete.

function Fade (start : float, end : float, length : float, currentObject : GameObject) { //define Fade parmeters if (currentObject.guiTexture.color.a == start){

for (i = 0.0; i < 1.0; i += Time.deltaTime*(1/length)) { //for the length of time currentObject.guiTexture.color.a = Mathf.Lerp(start, end, i); //lerp the value of the transparency from the start value to the end value in equal increments yield; currentObject.guiTexture.color.a = end; // ensure the fade is completely finished (because lerp doesn't always end on an exact value) } //end for

} //end if

} //end Fade

function FlashWhenHit (){ Fade (0, 0.8, 0.5, GUITextureobjectname); yield WaitForSeconds (.01); Fade (0.8, 0, 0.5, GUITextureobjectname); }

Here is the code. I am not sure what to put under GUITextureobjectname? Also, where do I attache the GUITexture, on the player?

Thanks for any help.

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
Best Answer

Answer by Eric5h5 · Apr 03, 2011 at 09:24 PM

You don't attach the GUITexture to anything, just have it be somewhere in the scene. For GUITextureobjectname you use a reference to the GUITexture. i.e., "var myTexture : GUITexture;"

Comment
Add comment · 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
0

Answer by AVividLight · Apr 03, 2011 at 07:47 PM

Sorry I don't have time to explain this... Just add a red texture, and through a script call "Fade Out"

var fadeOutTexture : Texture2D; var fadeSpeed = 0.3;

var drawDepth = -1000;

//-------------------------------------------------------------------- // Private variables //--------------------------------------------------------------------

private var alpha = 1.0;

private var fadeDir = -1;

//-------------------------------------------------------------------- // Runtime functions //--------------------------------------------------------------------

function OnGUI(){

 alpha += fadeDir * fadeSpeed * Time.deltaTime;  
 alpha = Mathf.Clamp01(alpha);   

 GUI.color.a = alpha;

 GUI.depth = drawDepth;

 GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), fadeOutTexture);

}

//--------------------------------------------------------------------

//--------------------------------------------------------------------

//--------------------------------------------------------------------

function fadeOut(){ fadeDir = 1;
yield WaitForSeconds (0.5); fadeDir = -1; }

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 Eric5h5 · Apr 03, 2011 at 09:22 PM 1
Share

That's not a good idea, because then you're drawing an alpha texture over the screen all the time, regardless of whether the screen should be flashing or not (which means potentially big fill-rate hit depending on hardware).

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

No one has followed this question yet.

Related Questions

Respawn with damage nwh 1 Answer

Damage Indicator not showing correct position of attack. 0 Answers

Please, I need a damage script 2 Answers

Looking for skilled individual to assist with problem 1 Answer

Setting up smart damage taking in game... 2 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