OnClick function getting wrong values from script? PLEASE HELP
Hello,
So I'm making a puzzle game (you can check it out here for the overwier https://store.steampowered.com/app/1190160/LIT_Bend_the_Light/).
Basically the game makes a screenshot everytime you solve a level in a new way, and then you can preview your solutions in a galery.The galery is animated so I have little functions for triggering the correct animations when the player wishes to see a solution.
SolutionScreens is the list containing all the solutionscreenshots and currentlyChosenSolution is index of well the solution that is currently being shown. Im using the "ToNextSolution" method in "onClick" function of a button. The problem is that the debug shows me 0 for both currentlyChosenSolution and solutionScreens.Count (wrong values) which does not match the values shown in inspector (correct values). Furthermore, when I'm calling the ChoseSolution method from code somewhere else, the values are printed correctly to the console. What am I missing?
public void ChoseSolution(int chosenIndex)
{
Debug.Log("New chosen index is:" + chosenIndex + "currentlyChosenSolution is: " + currentlyChosenSolution + "screens count: " + solutionScreens.Count);
if (chosenIndex > currentlyChosenSolution)
{
if (currentlyChosenSolution >= 0)
{
solutionScreens[currentlyChosenSolution].animator.Play("SlideCentreToLeft");
}
solutionScreens[chosenIndex].animator.Play("SlideRightToCentre");
}
else if (chosenIndex < currentlyChosenSolution)
{
solutionScreens[currentlyChosenSolution].animator.Play("SlideCentreToRight");
solutionScreens[chosenIndex].animator.Play("SlideLeftToCentre");
}
currentlyChosenSolution = chosenIndex;
}
public void ToNextSolution()
{
// I DONT GET WHY AM I GETTING 0 HERE. INSPECTOR IS SHOWING SOMETHING ELSE!!!!!
Debug.Log($"CurrenltyChosenSolution {currentlyChosenSolution}; SolutionScreenCount; {solutionScreens.Count} ");
if (currentlyChosenSolution < solutionScreens.Count -1)
{
ChoseSolution(currentlyChosenSolution + 1);
}
}
Your answer
Follow this Question
Related Questions
UnityEvent NullreferenceException in inspector 0 Answers
Button AddListener - pass in a UnityAction 0 Answers
Function Not Appearing In OnClick Editor 11 Answers
UnityEvent Generic (Inspector Serialization) 0 Answers
UnityEvent like Button? 0 Answers