public variable is not being updated in script.
I've done my fair share of googling and I can't figure out why this is doing what its doing. I'm making a 2.5d Platformer. I have a character script that the other scripts are inherited from. Inside the character script I have a bool isFacingLeft. I also have a function inside character that takes care of flipping the character to face the right way depending in which way the horizontal axis is set. In my horizontalMovement script I have a CheckDirection function that checks which way I'm facing and if I'm "moving" the other direction it calls to Flip() in the character script to swap model directions.
I'm going to show you my CheckDirection Method and my Flip method because in CheckDirection we set the isFacingLeft bool directly above the Flip() call. but in Flip I inserted a debug and its always getting called false.
protected virtual void CheckDirection()
{
// If Character is moving right
if(currentSpeed > 0)
{
if(character.isFacingLeft)
{
character.isFacingLeft = false;
Flip();
}
if(currentSpeed > maxSpeed)
{
currentSpeed = maxSpeed;
}
}
// If character is moving left
if(currentSpeed < 0)
{
if (!character.isFacingLeft)
{
character.isFacingLeft = true;
Flip();
}
if(currentSpeed < -maxSpeed)
{
currentSpeed = -maxSpeed;
}
}
}
And here is my Flip() function...
public virtual void Flip()
{
Debug.Log("isFacingLeft BOOL is: " + isFacingLeft.ToString());
if (isFacingLeft || (!isFacingLeft && isWallSliding))
{
//Debug.Log("Facing Left");
transform.rotation = Quaternion.Euler(0, -90, 0);
}
if (!isFacingLeft || (isFacingLeft && isWallSliding))
{
//Debug.Log("Facing Right");
transform.rotation = Quaternion.Euler(0, 90, 0);
}
}
The problem is that in the checkdirection i set the bool isFacingLeft to true directly above the Flip() method. but in the debug of Flip() it still has a value of false. I have tried using a getter/setter and in visual studio I check for all references of possible places that might change that value directly and the only place the does this is in the Checkdirection method. Everywhere else in my code just "gets" the value. As another troubleshoot attempt I added a debug.Log in the setter to show me when it gets changed. When I press play and walk left I get a true from the setter debug, but I get a false from the debug inside the Flip method with the exact same timestamp.
Oh I have also tried to make the public [System.NonSerialized] as well as someone pointed out in another forum answer. One last test as well... In the inspector I can see the bool changing as I turn left or right. So this is why I'm confused as to whats going on.
Thanks ahead of time for any help anyone might give.
Your answer
Follow this Question
Related Questions
Inheriting values from base class in c# 0 Answers
How to inherit a boolean 2 Answers