• 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 Pusiekkg · Jun 08, 2014 at 09:34 PM · photontagschanging

[Photon & tags]Tags changing & interaction problem.

Hi! At the beginning I want to sorry about my language.

My problem is, that I'm creating a "Tag game". You know the rules. If you are tag, you need to catch other player, if not, you need to run escape. I'm doing it Online with photon. When >2 players are in Game, my code is using Random to choose one of them to be the Tag( this one who is catching). This one is running with other animation( called "Catch") and when the distance between him and other character with tag "Player" is < 3(less than 3) he can catch him. Then tags should change, the one with tag "isTag" should be now "Player", and "Player" should be "isTag". I did it in many different ways. The closest one was this: Random Tag choosing

 public class tagMaking : MonoBehaviour {
     GameObject[] tab;
     int playersIn;
     bool blocker = false;
     GameObject player;
     GameObject isTag;
     float dist;
 
 
 
 
 
 
     
     // Update is called once per frame
     void Update () {
         if(blocker ==false){
         tab = GameObject.FindGameObjectsWithTag ("Player");
         if (tab.Length > 1) {
             GameObject changer = tab[Random.Range(0,tab.Length)];
             changer.tag="isTag";
                 changer.GetComponent<isTag>().enabled=true;
                 blocker=true;
             }
         }
 
     }


This is tag changing script:

  public class isTag : MonoBehaviour {
     float dist;
 
     
     // Update is called once per frame
     void Update () {
     GameObject    notTag= GameObject.FindWithTag("Player");
     GameObject    berek = GameObject.FindWithTag("isTag");
         dist = (transform.position - notTag.transform.position).magnitude;
     if (gameObject.tag=="isTag" && Input.GetKey (KeyCode.W)){
                         animation.Stop ("Walk");
                         animation.CrossFade ("Catch");
     }
     if (gameObject.tag == "isTag" && dist <= 3 && Input.GetKey (KeyCode.E)) {
             berek.GetComponent<isTag>().enabled = false;
             berek.tag = "Player";
             notTag.tag = "isTag";
             notTag.GetComponent<isTag>().enabled = true;
                 }
 }
 
 }

At this time those scripts are working until the Tag, who is local(master) won't catch other player. Then he gives his Tag to him, and this one is called now "isTag",his script is enabled, but can't give it away. Of course the first one, who was "isTag", now is "Player", has got script disabled, but still can catch others...

If someone could help me, I will be veeeery grateful.

Regards, Kuba

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Accessing the different position of a game object with same tags 1 Answer

Tags do not appear on objects 0 Answers

Changing between two cameras in an array error 1 Answer

Adding elements to a list is changing the initial values. Need help! 0 Answers

Begone / multiplayer 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