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 flexrails · Dec 04, 2009 at 08:53 AM · gameobjectmaterialrenderertransparencyvisibility

appear/disappear gameobject

hi, i've created several gameobjects in my scene. now at runtime i want only a few to be shown at startup. later i'd like to have some gameobjects fade away and completely disappear, while others to appear fading in. how do i do that in a generic way, i. e. a function taking the object id as param? how do i tween material alpha using Ani.Mate generically? thanks, flexrails

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

3 Replies

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

Answer by duck · Dec 04, 2009 at 10:00 AM

To make them appear and dissappear (without fading) is very simple. Just enable or disable each game object's renderer component. Here's the example from the docs:

// make the object invisible renderer.enabled = false;

// make the object visible renderer.enabled = true;

// toggle object's visibility each second function Update () {

 // Find out whether current second is odd or even
 var seconds : int = Time.time;
 var oddeven = (seconds % 2) == 0;

 // Enable renderer accordingly
 renderer.enabled = oddeven;

}

For fading individual game objects in and out, you'll need to use one of the shaders from the "Transparent" family, then adjust the alpha value of the main colour, for each gameobject's material.

Note that when you modify a game object's material using Renderer.material, you actually create a temporary clone of that material so that it is no longer shared with other gameobjects. This means you'll be able to fade gameobjects individually even though they may share the same material in the editor. Any clones that are made at runtime like this are cleaned up and re-set when you click stop.

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
3

Answer by flexrails · Dec 04, 2009 at 01:00 PM

that's what i ended up with for tweening alpha material using AniMate. hope it helps.

function TweenToAlpha(object:GameObject, duration:float, toAlpha:float) { var renderers = object.GetComponentsInChildren(Renderer); var materials:Array = []; for (var r in renderers) { for (var m in r.materials) { materials.Push(m); } }

 for (var m in materials) {
     Ani.Mate.To(m, duration, {"colorName": "_Color", "a": toAlpha});    
 }
 yield WaitForSeconds(duration);

}

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
1

Answer by elevishstar · Dec 04, 2009 at 10:19 AM

For switching between multiple game objects look also at the answers provided to this question: http://answers.unity3d.com/questions/1124/how-to-change-my-character-during-the-game/

Comment
Add comment · Show 2 · 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 OnlineCop · Mar 08, 2012 at 08:40 PM 0
Share

@elevishstar: updated link: http://answers.unity3d.com/questions/8632/how-to-change-my-character-during-the-game.html

avatar image AkooleGame · Dec 01, 2014 at 11:00 AM 0
Share

Even the updated link is broken.

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

1 Person is following this question.

avatar image

Related Questions

Changing two different objects renderer colour 1 Answer

Rendering an entire object as transparent 1 Answer

Change the alpha of a gameobject with multiple childs 1 Answer

Is there a shader in Unity that prevents transparent parts from overlapping? 1 Answer

Material class use general question 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