• 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 team_eden · Feb 01, 2015 at 05:04 PM · componentvalue

Value of var has no effect on Update loop()!?!

This script worked until I made it into a separate component. I get a debug.log that constantly displays the "Idle Panel Active" message, even though the 'actorAnimationCurrent' is being set to other values, which has been confirmed in the inspector. One person suggested to remove the script, and reimport it, that does not work either. I do have once curious fact though.

If I enable/disable this component while in play mode, all of a sudden works perfectly again.

The actionAnimationCurrent used to be sampled from another script, but it seems it would not update itself! So I set the target function to just change the menu script value manually, instead of having the menu script try to get it from the player.

This makes the actionAnimationCurrent update properly, but not the switch loop, or anything regarding the actual value of the animation String except the idle animation.

I noticed that if I remove the start values, the loop will not run, because idle animation was not being set anymore!! But after the first set, it never works again. WHY!!!

Would appreciate the help.

                                 var scriptActor:        scriptActor;
                                 var isPlayer:            boolean=false;
 
                                 var combatPanel:        GameObject;
                                 var idlePanel:            GameObject;
 
                                 var buttonHighlighted:    boolean=false;
                                 var actorAnimationCurrent:String="";
     
                 function Start ()
                     {    idlePanel=scriptActor.idlePanel;
                         combatPanel=scriptActor.combatPanel;    }
                         
                 function Update ()
                     {    if(isPlayer){doMenus();}    }

 function doMenus()
                     {    switch(actorAnimationCurrent)
                         {
                             case "Attack": Debug.Log("Attack Panel Active");
                                             if(!combatPanel.active)
                                             {    if(idlePanel.active)
                                             {    idlePanel.active=false;}
                                                 combatPanel.active=true; }
                                             break;
                             
                             case "Idle":    Debug.Log("Idle Panel Active");
                                             if(!idlePanel.active)
                                             {    if(combatPanel.active)
                                             {    combatPanel.active=false; }
                                                 idlePanel.active=true; }
                                             break;                                    
                             default:         break;
                         }
Comment
Add comment · Show 3
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 team_eden · Feb 08, 2015 at 06:57 PM 0
Share

I have since patched this by adding a GetComponent(myScriptHere).enabled during the Awake() function of the parent script, and making sure the target component is disabled by default. Seems to be working, although it concerns me, as why this has broken, and if it will break again.

avatar image meat5000 ♦ · Feb 08, 2015 at 07:06 PM 0
Share

$$anonymous$$ake isPlayer private.

Editor inspector values tend to override everything else.

Note that Start() only gets called once in the lifetime of the object. If for some reason the Object is disabled then re-enabled you must manually call Start() function to use it.

 function OnEnable()
 {
     Start();
 }


avatar image team_eden · Feb 16, 2015 at 02:24 AM 0
Share

This may be the solution, but I have not time to implement it. I will let you know when I do.

0 Replies

· Add your reply
  • Sort: 

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

19 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

Related Questions

adjusting Component values with scripts? 2 Answers

How to get a value from an array within another script. 1 Answer

2D Animation does not start 1 Answer

Find Script in parent Gameobject? 3 Answers

GetComponentsInChildren Network Reliable 0 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