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 averystrangeguy · May 27, 2013 at 05:57 PM · guitimealphasyntaxdot

A Question about Dot Syntax...

Am I using it right? I'm trying to make the health bar disappear after 5 seconds, but my script isn't running, and I know something's wrong. Can you help? Here's my code (it's UnityScript):

 var time: float = Time.time;
 var one : GameObject = GameObject.Find("/Health/1");
 
 function Update () {
     switch(time) {
         case 5:
             one.guiTexture.color.a(0.0);
         }
 };
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 Eric5h5 · May 27, 2013 at 06:02 PM

No, you have to assign a value.

 one.guiTexture.color.a = 0.0;

Some other problems: you assign Time.time to a variable called time but then never do anything with it, so time will always be 0.0. Why do you have that at all, instead of just using Time.time? However even if you removed that variable, you can't use Time.time in a switch statement, since it's highly unlikely it will ever be exactly 5.0. Also the "one" variable should only be declared outside a function; running code such as GameObject.Find should always be done inside a function, such as Start or Awake. Also "one" is not a good variable; use something more descriptive.

By the way, it would be a lot easier just to use Invoke for this anyway instead of Update.

Comment
Add comment · Show 5 · 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 averystrangeguy · May 27, 2013 at 06:18 PM 0
Share

Thanks a lot, but I wanted to make it so that after 5 seconds it becomes transparent... So how do I do that? Also, I thought Time.time was the amount of time since the game started, but you said it doesn't do anything... Now I'm confused...

avatar image Eric5h5 · May 27, 2013 at 06:22 PM 0
Share

As I said, use Invoke.

avatar image averystrangeguy · May 27, 2013 at 06:26 PM 0
Share

I'm still confused... Is this what you want me to do?

 function Start () {
     var one : GameObject = GameObject.Find("/Health/1");
 }
 
 function Invoke () {
     switch(Time.time) {
         case 5:
             one.guiTexture.color.a = 0.0;
         }
 };
avatar image Eric5h5 · May 27, 2013 at 06:33 PM 0
Share

No, not at all. Look up Invoke in the Unity documentation.

avatar image averystrangeguy · May 27, 2013 at 07:15 PM 0
Share

oh... got it...

 alert("Thanks a lot!!!");

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

14 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

Related Questions

Alpha set by tag in GUI.Label / GUI text behaves strange way 1 Answer

Alpha cutoff for a GUI Texture? 2 Answers

how to make a highlight gui ?? 1 Answer

How to draw GUI Text from code 1 Answer

Removing a GUITexture a set amount of time after it has been enabled. 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