- Home /
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?
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);
}
What makes you tell the variable does not change? You surely change the Reflex
variable somewhere else.
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).
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
}
}
}
When in this example have you assigned false to your variable?
it is always false in the inspector by some reason
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).
Your answer
Follow this Question
Related Questions
OnClick() animation 0 Answers
How do I make a function not appear on UnityEvents / Button OnClick lists? 0 Answers
Button OnClick() calling wrong function 1 Answer
How do i make the perfect button? 1 Answer
how to insert hover effect on unity button and active color button when the button is being click ? 0 Answers