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 chunjai · Feb 22, 2011 at 06:14 AM · gameobjectarrayclicklimitselect

Selecting One Piece, Moving to Selected Area

i have an array of gameobjects set up with a 'piece.js' script attached. here's what i'm having trouble with... i want to click one piece (with an OnMouseUp event) and have it sort of 'activate' to be moved. the problem is it activates everything. setting booleans inside that script didn't help, because it would just set true or false to everything the script is attached to.

i started to store the clicked object into an array like below ::

arr.Add(gameObject);

for (var go : GameObject in arr){ isSelected = true; }

this worked to an extent, but it then just adds objects to the array as i click them. is it possible to limit this array to 1 object? seems like something super basic but i'm at a loss.

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

1 Reply

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

Answer by · Feb 22, 2011 at 07:02 AM

Rather than "limiting the array to 1 object", just use a gameObject variable. i.e.

static var clickedObj : GameObject;

Alternatively - when you say "is it possible to limit this array to 1 object?", do you mean "is it possible to limit the array to 1 entry per object?" To do this, you'd iterate through the array, comparing whether or not the object already exists in the array before adding it.


Update as per comments:

You can store to the clickedObj variable simply by assigning with '='. i.e.

clickedObj = gameObject;
Comment
Add comment · Show 4 · 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 chunjai · Feb 22, 2011 at 08:01 AM 0
Share

is adding a gameobject to a gameobject possible? that'd probably be ideal, but i'd need to undo it as soon as the cycle completes. regarding the array, i meant limit .length to 1. sort of defeats the purpose of an array now that i think of it.

avatar image · Feb 22, 2011 at 10:48 AM 0
Share

Yeah, I would suggest just using a GameObject var rather than a 1-length array. It's not really 'adding' to an array, you're just storing a reference to the GameObject. I've updated my answer with how to 'store the clicked object'.

avatar image chunjai · Feb 23, 2011 at 06:01 AM 0
Share

hey dude, just wanted to say thanks for the help. it's really working out and fixed about a hundred problems. cheers.

avatar image · Feb 23, 2011 at 07:32 AM 0
Share

No troubles at all, glad I could help!

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

No one has followed this question yet.

Related Questions

selected object in array lost in translation 0 Answers

script optimization (choosing an object in game by click) 1 Answer

add waypoint to transform[] 2 Answers

Transport unknown amout of objects with GameObject array 0 Answers

View an array of the transform position/rotation of all game objects with a specified tag., 0 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