Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by awplays49 · Dec 03, 2014 at 09:04 AM · priority

Code seems to be giving priority to the first if written rather than giving them equal value

So I made a follower switcher, and I had this problem before, but I forgot what I did to fix it. Here's my code:

 using UnityEngine;
 using System.Collections;
 
 public class OneFollower : MonoBehaviour {
 
     private Follower HumanFollowerGet;
     private Follower AlienFollowerGet;
     public Follower CurrentFollower;
 
     private bool HumanFollowerStateGet;
     private bool AlienFollowerStateGet;
     private bool CurrentFollowerStateGet;
 
     void Start () {
         HumanFollowerGet = GameObject.Find ("Human Follower").GetComponent <Follower> ();
         AlienFollowerGet = GameObject.Find ("Alien Follower").GetComponent <Follower> ();
     }
 
     void Update () {
         HumanFollowerStateGet = HumanFollowerGet.GetComponent <Follower> ().Following;
         AlienFollowerStateGet = AlienFollowerGet.GetComponent <Follower> ().Following;
 
         Debug.Log (HumanFollowerStateGet);
         Debug.Log (AlienFollowerStateGet);
 
         if (AlienFollowerStateGet == true)
         {
             ChangeFollower (AlienFollowerGet);    
         }
         if (HumanFollowerStateGet == true)
         {
             ChangeFollower (HumanFollowerGet);
         }
     }
 
     void ChangeFollower (Follower NewFollower) {
         if (CurrentFollower != null)
         {
             CurrentFollower.Following = false;
         }
         CurrentFollower = NewFollower;
         CurrentFollower.Following = true;
     }
 }

if I put HumanFollowerStateGet before AlienFollowerStateGet, for example, and then I approach the human follower, it works, then I approach the alien follower and then back to the human and the human Following state is in both true and false if im within the meet distance. It is supposed to do this, but the code is arguing the command back and forth. I once fixed this without any additional code. Help?

Comment
Add comment · Show 4
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
avatar image NoseKills · Dec 03, 2014 at 08:31 PM 0
Share

What is the situation you are using this code in and what is this script attached to? And what is the desired behavior?

Where do you set Follower.Following to true initially?

If you set Follower.Following to true when you get close enough to either the alien or human, does this first follower then follow you so that when you reach the next one, you are simultaneously inside both meet distances?

In that case both HumanFollowerStateGet and AlienFollowerStateGet would be true in the next Update() which would probably cause unwanted behavior.

avatar image awplays49 · Dec 03, 2014 at 08:49 PM 0
Share

Follower.Following is set to true when the follower is in range of meeting up with the player, and is set to false when the player is too far away, two separate values. The OneFollower script is attached to both the followers.

avatar image awplays49 · Dec 03, 2014 at 08:49 PM 0
Share

@Nose$$anonymous$$ills

avatar image awplays49 · Dec 03, 2014 at 08:57 PM 0
Share

This worked once but i restarted the game because i lost half the data. This is exactly how I did it last time though. $$anonymous$$y intentions is that when a second follower is in range, get rid of the first.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to set starting order of scripts? 2 Answers

Is there a way to prioritise a certain touch input over another one? 0 Answers

Tips on managing animation states 2 Answers

Prioritize Movement in 2D 3 Answers

Physic Material Friction Combine Mode lack of documentation? 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