• 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 MajorParts · Jun 25, 2015 at 01:06 PM · c#image effects

Changing ScreenOverlay Intensity

I have a blood splat effect using the ScreenOverlay image effect when my player is hit. I want this to fade away over a few seconds but it won't!

The intensity is set to 0 to begin with and when the player gets hit, I start a coroutine to change it to 1, then waitforseconds(0.2f), then set to 0.8, then wait...etc etc

When the player is hit, the splat appears on screen with intensity 1 but stays at 1 and doesn't reduce and I have no clue as to why!

This is the coroutine....

 IEnumerator Splatter ()
     {
         splatFX.intensity = 1f;
         yield return new WaitForSeconds (0.2f);
         splatFX.intensity = 0.8f;
         yield return new WaitForSeconds (0.2f);
         splatFX.intensity = 0.6f;
         yield return new WaitForSeconds (0.2f);
         splatFX.intensity = 0.4f;
         yield return new WaitForSeconds (0.2f);
         splatFX.intensity = 0.2f;
         yield return new WaitForSeconds (0.2f);
         splatFX.intensity = 0f;
     }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by felixpk · Jun 25, 2015 at 01:10 PM

Hi, first of all you wouldn't code that like that, try this:

 public IEnumerator SplashEffect() {
     while(splatFX.intensity >= 0) {
         splatFX.intensity -= 2 * Time.deltaTime; // 2 = effect duration / velocity
         yield return new WaitForFixedUpdate();
     }
 }

Next step is that I have no clue what splatFX is, so I can't say if splatFX.intensity is teh right way to set the visibility in the game.

Comment
Add comment · Show 7 · 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 MajorParts · Jun 25, 2015 at 01:31 PM 0
Share

splatFX is the ScreenOverlay component

I tried your routine but with splatFX.intensity = 1 before the "while"...the intensity still doesn't reduce by anything though.

I realise it's not the best way to do it, but I tried a way that I thought would work 1st before trying to optimize it in any way.

avatar image MajorParts · Jun 25, 2015 at 01:47 PM 0
Share

I added Debug.Log ("waited") after each wait and nothing is put to the console, so the code is not going past the 1st splatFX.intensity or 1st waitforseconds

avatar image felixpk · Jun 25, 2015 at 01:50 PM 0
Share

How are you calling the Coroutine? Do you use StartCoroutine(SpalshEffect()); ?

avatar image MajorParts · Jun 25, 2015 at 01:53 PM 0
Share

It seems WaitforSeconds isn't working! I just replaced the whole routine with a simple

print(Time.time); yield return new WaitForSeconds(5); print(Time.time);

and it only ever prints the 1st time! What's going on?

avatar image DiegoSLTS · Jun 25, 2015 at 02:05 PM 1
Share

$$anonymous$$aybe you're destroying or deactivating the ScreenOverlay object? When you do that on an object that started a coroutine, the coroutine stops.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

22 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Making a bubble level (not a game but work tool) 1 Answer

An OS design issue: File types associated with their appropriate programs 1 Answer

Blur Effect 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