• 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 Giga0098 · Nov 05, 2020 at 08:11 PM · functionboolvoid

I'm having problems with bools resetting within a function

Hi,

I'm quite new to programming and I might have overestimated my abilities. I'm trying to build a small Game with a few Tiles moving along a grid made out by Waypoints. Long story short, I'm trying to call a function which declares the exact position and moves the tile accordingly.

My Problem each frame the bool (Moving) telling the tile to move is reset and nothing happens...

 void IStepsRight(int Steps, GameObject Tile, bool Moving, bool HalfwayMoved, bool StartSet, Vector3 Start, Vector3 Ziel, Vector3 Zwischenschritt)
     { 
         //bool Moving = new bool();
         //bool HalfwayMoved = new bool();
         //bool StartSet = new bool();
         //Vector3 Start = new Vector3();
         //Vector3 Ziel = new Vector3();
         //Vector3 Zwischenschritt = new Vector3();
         
 
         Debug.Log(Moving);
         Debug.Log(Steps);
         if (Tile.gameObject.transform.position.x == IA.transform.position.x && StartSet == false) { Debug.Log("IA"); Start = IA.transform.position; StartSet = true; }
         else if (Tile.gameObject.transform.position.x == IB.transform.position.x && StartSet == false) { Debug.Log("IB"); Start = IB.transform.position; StartSet = true; }
         else if (Tile.gameObject.transform.position.x == IC.transform.position.x && StartSet == false) { Debug.Log("IC"); Start = IC.transform.position; StartSet = true; }
         else if (Tile.gameObject.transform.position.x == ID.transform.position.x && StartSet == false) { Debug.Log("ID"); Start = ID.transform.position; StartSet = true; }
 
         if (Steps == 1 && Start != null && Moving == false && StartSet) 
         {
             Debug.Log("Steps == 1 && Start != null && Moving == false");
             if (Start == IA.transform.position) { Ziel = IB.transform.position; Zwischenschritt = IA_B.transform.position; Moving = true;}
             else if (Start == IB.transform.position) { Ziel = IC.transform.position; Zwischenschritt = IB_C.transform.position; Moving = true;}
             else if (Start == IC.transform.position) { Ziel = ID.transform.position; Zwischenschritt = IC_D.transform.position; Moving = true;}
             else if (Start == ID.transform.position) { Ziel = IA.transform.position; Zwischenschritt = ID_A.transform.position; Moving = true;}
         }
         else if (Steps == 2 && Start != null && Moving == false && StartSet)
         {
             Debug.Log("Steps == 2 && Start != null && Moving == false");
             if (Start == IA.transform.position) { Ziel = IB.transform.position; Zwischenschritt = IA_B.transform.position; Moving = true;}
             else if (Start == IB.transform.position) { Ziel = IC.transform.position; Zwischenschritt = IB_C.transform.position; Moving = true;}
             else if (Start == IC.transform.position) { Ziel = ID.transform.position; Zwischenschritt = IC_D.transform.position; Moving = true;}
             else if (Start == ID.transform.position) { Ziel = IA.transform.position; Zwischenschritt = ID_A.transform.position; Moving = true;}
         }
         else if (Steps == 3 && Start != null && Moving == false && StartSet)
         {
             Debug.Log("Steps == 3 && Start != null && Moving == false");
             if (Start == IA.transform.position) { Ziel = IB.transform.position; Zwischenschritt = IA_B.transform.position; Moving = true;}
             else if (Start == IB.transform.position) { Ziel = IC.transform.position; Zwischenschritt = IB_C.transform.position; Moving = true;}
             else if (Start == IC.transform.position) { Ziel = ID.transform.position; Zwischenschritt = IC_D.transform.position; Moving = true;}
             else if (Start == ID.transform.position) { Ziel = IA.transform.position; Zwischenschritt = ID_A.transform.position; Moving = true;}
         }
         
         if (Moving == true)
         {
             Debug.Log("Moving!!!");
             Debug.Log("Start " + Start);
             Debug.Log("Zwischenschritt " + Zwischenschritt);
             Debug.Log("Ziel " + Ziel);
             Debug.Log("Position " + Tile.gameObject.transform.position);
             Tile.gameObject.transform.position = Vector3.MoveTowards(Tile.gameObject.transform.position, Zwischenschritt, Speed * Time.deltaTime);
             Tile.gameObject.transform.rotation = Quaternion.RotateTowards(Tile.gameObject.transform.rotation, Quaternion.Euler(0f, 0f, 180f), Speed * Time.deltaTime);
             if (Tile.gameObject.transform.position == Zwischenschritt) 
             {
                 Debug.Log("Halfway through!");
                 HalfwayMoved = true;
             }
             if (HalfwayMoved)
             {
                 Tile.gameObject.transform.position = Vector3.MoveTowards(Tile.gameObject.transform.position, Ziel, Speed * Time.deltaTime);
                 Tile.gameObject.transform.rotation = Quaternion.RotateTowards(Tile.gameObject.transform.rotation, Quaternion.Euler(0f, 0f, 180f), Speed * Time.deltaTime);
             }
             if (Tile.gameObject.transform.position == Ziel) { HalfwayMoved = false; Moving = false; StartSet = false; Steps -= 1; Debug.Log("Guess I'm done"); }
             
         }
         if (Moving == false) {Debug.Log ("Not Moving!"); }
         else if (Steps == 0 && Moving == false)
         {
             I.GetComponentInChildren<Clickable>().GotClicked = false;
         }
     }


I tried creating the variables directly in the code or feeding them in as parameters. Both lead to the same problem. this function will be called in multiple instances so I can't just use predefined variables.

I'm thankful for any input because I've been stuck for hours. Thanks!

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

142 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

Related Questions

Check if a function is no longer being called? 3 Answers

Problem with scripts ignoring my variables/functions? 0 Answers

Sending a message from javascript to C# 1 Answer

How can I stop executing a Function in a void Function? 1 Answer

How can I access a bool for a specific gameObject from the foreach loop? 2 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