Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by karlkevin · Mar 14, 2016 at 10:23 AM · fadefadeoutpicturefade outinstructions

How to fade out picture

@karlkevin

I am making a "instructions picture", where picture should fade out after starting the scene, atm i have made this

using UnityEngine; using System.Collections;

public class Fade : MonoBehaviour { float duration = 2;

 void Update() {
     if (Time.time > duration) {
         Destroy (gameObject);
     }
 
 
 }

}

and as you can see, it just destroys itself after 2 seconds, but I want to fade it, for example over 1 second. And if you know how to even make it like in flappy bird used to have, that after touching the screen, it fades out, not after 2 seconds. I hope you undrestand what I mean and I hope you can help me with this simple problem. Thank you for helping! :)

Comment
Add comment · Show 2
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 Zoogyburger · Mar 15, 2016 at 08:30 PM 1
Share

You need a Renderer attached to your "Instructions picture" gameobject. If it's a Sprite give it a Sprite Renderer etc.

If you have this line without a Renderer it won't know what to get:

 GetComponent<Renderer>
avatar image karlkevin Zoogyburger · Mar 16, 2016 at 11:42 AM 0
Share

Thank you, I tried to use it with texture, so that was problem, but works now. Thank you very much! :)

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Rajeesh_AR · Mar 15, 2016 at 10:26 AM

Hi @karlkevin ,

Try this,

float fadePerSec = 1.5f;

  private void Update() {
      var material = GetComponent<Renderer>().material;
      var color = material.color;
      material.color = new Color(color.r, color.g, color.b, color.a - (fadePerSec * Time.deltaTime));
  }
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 karlkevin · Mar 15, 2016 at 08:15 PM 0
Share

Hey @Rajeesh_AR Thank you for helping, but since im beginner, i dont know what "Renderer" means and i get an error:

$$anonymous$$issingComponentException: There is no 'Renderer' attached to the "Image (4)" game object, but a script is trying to access it. You probably need to add a Renderer to the game object "Image (4)". Or your script needs to check if the component is attached before using it.

I hope you can help me with this little thing also :) Thank you :)

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

What's the easiest way to fade a sprite in? - Looking for equiv of jQuery's fadeIn() 0 Answers

How do I make the camera move forward via C# script? 0 Answers

ScreenFade Help 1 Answer

[SOLVED]Fade in Fade out problem 1 Answer

How i can check alpha level (RGBA) an UI obj? 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