• 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 blueGaia · Oct 01, 2011 at 08:13 PM · tagcheck

check if Go.tag is this instance of the object

 //left click Unit, Select it
 if (Input.GetMouseButtonDown(0) && object.tag == "Unit"){ 
     //check it is me???
     selected = true;
 }

at the moment all instances get selected.

Comment
Add comment · Show 1
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 blueGaia · Oct 01, 2011 at 08:15 PM 0
Share

*NB : object is set via Raycast from screen to mouse position.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by save · Oct 01, 2011 at 08:53 PM

My best guess is that you should make one or more variables private. The actual selected object should be a static variable which makes a reference to a GameObject.

static var selectedObject : GameObject;

if (selectedObject==this.gameObject)

An even better approach would be to have an overhead which checks if something is selected, then takes over parts of the GameObjects regular script. If you have lots of objects checking "if I am this" you'll notice a slight impact on performance. But instead letting one function control that part for the selected object will make a more clean and effective pipeline.

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Is there something like clicked.gameObject? 3 Answers

OverlapSphere, check how many object with specific tag did it collide with.. 2 Answers

Why is this Raycast not working ? 3 Answers

Physics.CheckSphere with tag 1 Answer

Tiny tag changing and checking problem 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges