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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by InsideOutMonkie · Jun 19, 2012 at 06:32 AM · collidertimerfadecomponentsdelta

Delta component

I have a part of a script that I found on another question.

function OnTriggerEnter(other:Collider) { if(other.name=="Player") //Player entered the trigger Camera.main.GetComponent(MotionBlur).enabled=true; }

Im using it to trigger a component (In my case an image effect) to enable itself and disable when I touch an object. So my question now is, How do I go about setting up the script so that, when you touch an object the Component slowly fades in, stay on for a minute, then slowly fade out again.

Any one have any ideas of how i would go about this. My guess is it will deal with some kinda delta? Please please help somebody, I really have no idea how to script on my own.

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 hijinxbassist · Jun 19, 2012 at 11:13 PM

You will use Lerp to ease the values of the blur in. A good way to do this is to set all the values like normal in the inspector. In the script make a var for each float value of the image effect. Then in start set those values to 0.

 private var fading:boolean;
 private var canFadeIn:boolean=true;
 private var blurSpread:float; 
 private var orgBlueSpread:float;
 private var blur:Blur;

 function Start()
 {
     blur=Camera.main.transform.GetComponent(Blur);
     orgBlurSpread=blur.blurSpread;
     blur.blurSpread=0;
 }
 function OnTriggerEnter(other:Collider)
 {
     if(!fading)
     {
         if(canFadeIn)Fade(false);
         else Fade(true);
     }
 }
 function Fade(out:boolean)
 {
     fading=true;
     var t:float=0;
     var lerpTime:float=1.5;
     var start:float;
     var target:float;
     if(out)
     {
         start=orgBlurSpread;
         target=0;
         canFadeIn=true
     }
     else
     {
         start=0;
         target=orgBlurSpread;
         canFadeIn=false
     }
     while(t<1)
     {
         blur.blurSpread=Mathf.Lerp(start,target,t);
         t+=Time.deltaTime/lerpTime;
         yield;
     }
     fading=false;
 }
Comment
Add comment · Show 8 · 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 InsideOutMonkie · Jun 19, 2012 at 11:26 PM 0
Share

on line 23 it says, Unexpected token: in also on line 23 it says, Expecting EOF, found boolean

avatar image Bunny83 · Jun 20, 2012 at 03:45 AM 1
Share

"in" is propably a bad variable name, try something else ;)

in is actually a keyword which is used in a for-each loop

avatar image hijinxbassist · Jun 20, 2012 at 05:15 AM 0
Share

hahahahaH! wow, totally missed that one, dumb mistake Thanks

avatar image InsideOutMonkie · Jun 20, 2012 at 06:38 AM 0
Share

Amazing it works! There are no errors! But it works in a strange way haha Right now, when you touch the cube, the effect fades in as expected But it doesnt fade itself out, you have to touch the cube again to make it fade out. When I read your script, it appears as if it says. the effect will fade in, stay on for awhile, then slowly fade back out. (which would function much nicer if possible).

avatar image hijinxbassist · Jun 20, 2012 at 07:11 AM 0
Share
     fading=true;
     var t:float=0;
     var lerpTime:float=1.5;
     var start:float;
     var target:float;
 
     for(var i:int=0;i<2;i++)
     {
         if(i==0)
         {
             start=0;
               target=orgBlurSpread;
               canFadeIn=false
         }
         else
         {
             start=orgBlurSpread;
             target=0;
             canFadeIn=true
         }
         while(t<1)
         {
             blur.blurSpread=$$anonymous$$athf.Lerp(start,target,t);
             t+=Time.deltaTime/lerpTime;
             yield;
         }
         
         //This is a delay for the Fade Out portion 'if "i" equals zero'
         //means we just faded the effect in, so we need to delay 
         //the next run of the previous code(for i<2, "(i=0,i=1) ==2 loops")
         //next time (when i==1) this delay wont happen bcz theres no reason
         if(i==0)
         {
             var nt:float=0;  
             while(nt<1)
             {         //fadeOutDelay is how long until fade out starts
                 nt+=Time.deltaTime/fadeOutDelay;
                 yield;
             }
         }
     }
     fading=false;
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Need some help an object collider that stops a timer then displays it on another scene 1 Answer

Character controller not fitting through door 0 Answers

Need help with game points and trigger 2 Answers

Fading Object in and out with timer 1 Answer

Start/Stop Timer when player enters/exits a specific space? 1 Answer


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