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 benfattino · Sep 24, 2012 at 05:58 PM · objectchildfadegroup

Fade between group of object

I'm using this script to fade two groups of object. Script automatically pick all child of two object and fade between them. All object have material with alpha channel. Script working, but is not fluid. I'm a novice programmer. Can anyone tell me if I'm doing something wrong by accident? Thanks.

 #pragma strict
 
 var OBJFirst : GameObject;
 var OBJSecond : GameObject;
 private var OBJFirstArray : Component[];
 private var OBJSecondArray : Component[];
 var AlphaStartFirst : float = 0.0;
 var AlphaStartSecond : float = 0.0;
 var SingleTouch : boolean = true;
 var DoubleTap : boolean = false;
 var Swipe : boolean = false;
 var AlphaHigh : float = 1.0;
 var AlphaLow : float = 0.0;
 private var alphaFirst : float ;
 private var alphaSecond : float ;
 var velocity : float = 1.0;
 var TimeDelay : float = 0.0;
 private var time : float;
 private var var_Fade : boolean;
 private var GoTouch : boolean = true;
 
 function Awake () {
 GetComp();
 alphaFirst = AlphaStartFirst;
 alphaSecond = AlphaStartSecond;
 }
 
 function Start () {
 }
 
 function Update () {
 if (var_Fade){
 fun_Fade();
 }
 }
 
 
 
 function fun_Fade(){
      
 
      if( alphaFirst > 0){
      for (var child1 : Component in OBJFirstArray) {
           child1.renderer.material.color.a = alphaFirst;
             
      for (var child2 : Component in OBJSecondArray) {
         child2.renderer.material.color.a = alphaSecond;
         }
      time = time + Time.deltaTime*1/velocity;
      alphaFirst = Mathf.Lerp(AlphaHigh,AlphaLow,time);
      alphaSecond = Mathf.Lerp(AlphaLow,AlphaHigh,time);
      }
      else if (alphaFirst == 0){
      var_Fade = false;
      OBJFirst.SetActiveRecursively(false);
      Manager.GoTouch = true;
      }
      }
      
 
 function GetComp(){
 OBJFirstArray = OBJFirst.GetComponentsInChildren(Component);
 OBJSecondArray = OBJSecond.GetComponentsInChildren(Component);
 }   
 
 
 function On_TouchStart(gesture:Gesture){
 if (Manager.GoTouch){
 if (SingleTouch){
 Manager.GoTouch = false;
 alphaFirst = AlphaHigh;
 alphaSecond = AlphaLow;
 OBJSecond.SetActiveRecursively(true);
 yield WaitForSeconds (TimeDelay);
 var_Fade = true;
 }
 }
 }
 
 
 
 
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 shaderop · Sep 24, 2012 at 06:31 PM 0
Share

$$anonymous$$aybe you could explain what you mean by "not fluid." Is the fading changing in steps? Is it too sudden?

Anyways, you should probably rewrite this using a tweening library like iTween. It will make your code easier to read and maintain, and, who knows, it might solve your issue as well.

avatar image benfattino · Sep 24, 2012 at 07:24 PM 0
Share

Yes, the fading changing in steps, subtle but annoying. I will try to do something with itween... Thanks.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Sep 24, 2012 at 09:13 PM

I would change this:

 private var OBJFirstArray : Component[];
 OBJFirstArray = OBJFirst.GetComponentsInChildren(Component);
 for (var child1 : Component in OBJFirstArray)
   child1.renderer.material.color.a = alphaFirst;

to this:

 private var OBJFirstArray : Renderer[];
 OBJFirstArray = OBJFirst.GetComponentsInChildren(Renderer);
 for (var child1 : Renderer in OBJFirstArray)
   child1.material.color.a = alphaFirst;
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.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Fade out the image when it touches certain object. 0 Answers

SteamVR Door handle .. Door, Hinge Joint not Circle Drive. 0 Answers

How to Make Part of Object Between Camera and Player Transparent 2 Answers

Do Child Objects Trigger Parent Objects? 1 Answer

How to move a group of objects with rigidbodies together? 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