Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 guiviana334 · May 11, 2019 at 10:20 PM · buttonvariablesbooleanbutton trigger eventsonclick

My button does not assign any variable value,My OnClick button works with Debug.Log, but doesnt assign any values it should

i have a button on screen that should call this function

public void ReflexButton() { Reflex = true; Debug.Log("pao"); }

but when i click it, the Debug.Log part works, but there's no change in the variable value, can anyone help me?

,i have a button on the screen that should call this function:

 public void ReflexButton()
 {
     Reflex = true;
     Debug.Log("works");
 }

but every time i press it, the console prints "works", but the variable does not change, not even a sudden true then false, it just dont work, can anyone help me?

Comment
Add comment · Show 10
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 Zaeran · May 11, 2019 at 10:25 PM 0
Share

Can you post your whole script?

avatar image guiviana334 Zaeran · May 12, 2019 at 03:21 PM 0
Share

The whole script deals with all interactions with the ball, it would be many unused information, but sure, i can post the parts where Reflex is used

 public void ReflexButton()
 {
     Reflex = true;
     Debug.Log("Reflex="+Reflex);
 }

 private void OnTriggerStay(Collider other)
 {
     if (other.gameObject.tag == "Ball")
     {
         if (Reflex == true && invulnerable == false)
         {
             Grab(other.gameObject);
             Reflex = false;
         }
     }
 }

 void Grab(GameObject ob)
 {
         ballison = true;
      
         ball = ob;

         ballfx.flamable = true;

         ballRB = ball.GetComponent<Rigidbody>();

         ball.transform.rotation = transform.rotation;

         ob.transform.position = hand.transform.position;

         ballRB.is$$anonymous$$inematic = true;

         ob.transform.SetParent(hand.transform);
     
 }
avatar image Hellium · May 11, 2019 at 10:27 PM 0
Share

What makes you tell the variable does not change? You surely change the Reflex variable somewhere else.

avatar image Bonfire-Boy Hellium · May 11, 2019 at 11:22 PM 0
Share

If you want to know if the variable's value has changed, put it in the logging.

 Reflex = true;
 Debug.Log("Reflex="+Reflex);

This should convince you that it does set the value. Either, like Helium says, something else is then changing it back, or you're just mistaken about its value (eg because you're looking at the wrong variable).

avatar image guiviana334 Bonfire-Boy · May 12, 2019 at 03:08 PM 0
Share

Your suggestion shows True as a value, but the function that is activated by it does not work now:

 private void OnTriggerStay(Collider other)
 {
     if (other.gameObject.tag == "Ball")
     {
         if (Reflex == true //the problem// && invulnerable //defined before// == false)
         {
             Grab(other.gameObject);
             Reflex = false; //the error was ongoing even before this line
         }
     }
 }


Show more comments
avatar image JoshuaOreskovich · May 11, 2019 at 11:24 PM 0
Share

When in this example have you assigned false to your variable?

avatar image guiviana334 JoshuaOreskovich · May 12, 2019 at 02:52 AM 0
Share

it is always false in the inspector by some reason

avatar image Bonfire-Boy guiviana334 · May 12, 2019 at 08:11 AM 1
Share

Have you tried the logging I suggested? Simply assigning a value to a variable doesn't fail. As you have been told, you're either setting it back to false, or not looking at the right variable (perhaps you have multiple instances of the component - something you could diagnose by also adding logging to show which gameobject it's being set on).

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.

Follow this Question

Answers Answers and Comments

132 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 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

Upgrade Button 3 & 4 calling on the Upgrade 2 method 1 Answer

onclick.addlistener only works once 0 Answers

On Click Add Listener not working on Game Object 4 Answers

OnClick() animation 0 Answers

How do I make a function not appear on UnityEvents / Button OnClick lists? 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