Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 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 /
  • Help Room /
avatar image
0
Question by technorocker · Nov 30, 2020 at 01:06 AM · variablesbooleaninheritance2.5d

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.

Comment
Add comment
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

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

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

Inheriting values from base class in c# 0 Answers

How to inherit a boolean 2 Answers

Can I have a variable accessed through the inspector and be accessed by a child script without making it public? 1 Answer

One variable handling two types without a mess 2 Answers

How can I access both classes from a single type? 1 Answer


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