• 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 srylain · Mar 22, 2017 at 06:20 PM · fadein

Fading in an object as it gets closer to the camera

http://i.imgur.com/lCOxks1.jpg

As you can see in the image, as notes come on-screen they fade in. I'm trying to replicate the effect, and was wondering how it could be done. It needs to be position based as well, since the notes can move at varying speeds and I don't want them to be halfway down the screen and still be fading in.

Comment
Add comment · Show 1
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 Gaming-Dudester · Mar 22, 2017 at 10:27 PM 0
Share

Hmmmm i dont know how to do it position based :/ maybe if you made the position equal to the objects alpha but devided by or times till it works to the size of your board. $$anonymous$$inda like make a color like

public Color testColor; public GameObject testObj;

And then

void Update() { testObj.GetComponent().color = testColor;

 testColor = testObj.position.y / 2.5;

}

This is entirely expiremental so don't get mad if it dosnt work :D thats why i commented it ins$$anonymous$$d of submitting it as an answer

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Mr-Men · Mar 23, 2017 at 12:34 PM

Place a script on your GameObject that alters the alpha of the object's colour based on the distance from the camera. Steps along the lines of:

 set maxDistance as the furthest an object can be away before it's completely transparent
 
 set distance = Mathf.Min(Vector3.Distance(Camera.main.transform.position, transform.position), maxDistance)
 
   set object colour alpha to 1 - (distance/maxDistance)

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 LucyLuna · Mar 23, 2017 at 03:27 AM

You can try this, I'm not sure if it works :

Raycast from the camera

Camera cam; RaycastHit hitinfo; float distance; Layermask targetMask;

void Update(){ if(Physic.Raycast(cam.transform.position,cam.transform.forward,out hitinfo ,distance,targetMask)){ if(hitinfo.transform.Comparetag("fadeObject")){ hitInfo.Getcomponent().Fade(); } } }

This way works for me almost all the time

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 lyonb · Mar 23, 2017 at 08:14 AM

You could have a Color lerp on the material that is based on the distance of the object from the camera

 Color color;
 Color invis;
 public GameObject object;
 Renderer objectRenderer;

 void Start(){
 //Get object's renderer
 objectRenderer = object.GetComponent<Renderer>();
 //store the material's color
 color = objectRenderer.material.color;
 //copy the color for the invisible color value
 invis = color;
 //set the alpha to 0 in the new color value
 ivis.a = 0;
 //make the object invisible to begin with
 objectRenderer.mater.color = invis;
 }
 
 void Update(){
 //get the distance between the camera and the object, assuming object to be the GameObject of the object that fades in
 float distance = (Camera.main.transform.position - object.transform.position).magnitude;
 if(distance > 10){
 //fade into the original color as the distance approaches 10 (assuming it started further away, and 10 being an arbitrary distance to check)
 objectRenderer.material.color = Color.Lerp(invis, color, 10/distance);
 }
 }

I haven't tested any of this, and this example assumes a lot of what it going on, and that there is something else controlling the movement of the object, but hopefully that puts you in the right direction

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

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

67 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 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 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 avatar image

Related Questions

Smoothly Fade in a texture 1 Answer

Fade in with CrossFadeAlpha 1 Answer

How do I fade up a light to fill a room evenly? 1 Answer

How do I lerp to a color? 1 Answer

Fade object in smoothly not working 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