• 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 PlatPlayz · Jan 25, 2018 at 06:50 PM · 3dtagfollow

Same objects following different tags in Unity3D

Hello! I've been trying to make an object follow another object, which I managed thanks to the community. The object follows his target fine, but here's the issue. I want to make objects of the same prefab follow targets with different tags. Is there a way to do that?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by PlatPlayz · Jan 27, 2018 at 07:38 PM

Thank you for your answers. I will just make a few prefabs with different follow tags to make it easier. I just wanted to make it cleaner using code, but that's too complicated for my level.

Comment
Add comment · Show 1 · Share
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 jman12EX · Jan 26, 2018 at 10:11 PM 0
Share

Doing it in the same prefab it not the way to go. You should make each of them a different prefab and name them accordingly. Then in the script ins$$anonymous$$d of haveing it where it says

{ Your_Variable.GetComponentTag<“player”>; }

You should make the script say

{ Public GameObject Track_This;

Your_Variable.GetComponentTag; }

This is so you can change it in the inspector

avatar image
1

Answer by LTonon · Jan 25, 2018 at 07:06 PM

Sure, you could create a string variable "followTag", for example, that has to be public or have an attribute [SerializeField], so you can see and change it on the script inspector. Then for each of those game objects in the scene you need to manually give a specific tag name to chase, using this followTag variable in your script to define what it's going to follow. Would this fix it, or this solution does not go along what you were thinking?

Comment
Add comment · Show 6 · Share
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 PlatPlayz · Jan 25, 2018 at 07:11 PM 0
Share

If I did it this way, would I not need to create multiple prefabs to follow different tags?

avatar image LTonon PlatPlayz · Jan 25, 2018 at 07:52 PM 0
Share

No, doing it this way you could have only one prefab, but everytime you this prefab to the scene you would have to give it a tag to follow manually on the inspector. All you have to do is avoid hitting "Apply", which would make all prefabs have the same tag to follow. It's okay for each prefab to have it's own characteristics when in scene.

avatar image PlatPlayz LTonon · Jan 25, 2018 at 07:54 PM 0
Share

But what if I wanted to instantiate them with script? Would that work?

Show more comments

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

81 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

Related Questions

Make Object Move to/follow Another Object? (plus turn towards it) 3 Answers

GUI Follow RaycastHit 2 Answers

How to make a follow AI 4 Answers

3D Text to follow FPS 1 Answer

Target a GameObject and follow it when it's near 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