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 lampshade · Jun 15, 2010 at 02:23 AM · gameobjectscriptingbasicsselection

GameObject.Find("In-Game-Object") Position

Hi,

I need to know if I need to make seperate script (to use transform.position) and then attach it to each game object to know about the individual positions.

public static Vector3 Object_1, Object_2, Object_3 Object_4, Object_5 ;

// Use this for initialization void Start () { if (GameObject.Find("Object_1")) { Object_1 = transform.position; } if (GameObject.Find("Object_2")) { Object_2 = transform.position; } if (GameObject.Find("Object_3")) { Object_3 = transform.position; } if (GameObject.Find("Object_4")) { Object_4 = transform.position; } if (GameObject.Find("Object_5")) { Object_5 = transform.position; } }

The above is in one script file, attached to each Object, [1,5]. The intention is to know about each objects individual position.

When I go to Debug.Log(Object_2) I see that it is either 0,0,0 (not true) or overwritten..However, Logging, Object_1 is fine...Is it true that I need to make seperate script for each game object?

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 johnsci911 · Feb 29, 2016 at 12:11 PM 0
Share

I want to find an object on a specific position. How can I do that?

2 Replies

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

Answer by Adrian Love · Jun 15, 2010 at 03:05 AM

Okay, So what objects are in your hierarchy?

I read your code like this:

When this object is loaded look for (Game)Objects 1 through 5 and save their positions into Vector3 objects labeled "Object_1" through "Object_5".

If you'd like to access the transform try something like this:

GameObject.Find("Object_1").transform.position;

Read more about selectors here: http://unity3d.com/support/documentation/ScriptReference/GameObject.Find.html

Each GameObject has a Transform component automatically: http://unity3d.com/support/documentation/ScriptReference/Transform.html

Also, you might want to try and use tags if you find yourself accessing a lot of the same type of object. read more about them here: http://unity3d.com/support/documentation/Components/Tags.html

Good luck with whatever you're doing. If you want more specific information try expressing what the overall goal is next time. :)

Comment
Add comment · Show 8 · 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 lampshade · Jun 15, 2010 at 03:12 AM 0
Share

The Object1,2,3,4,5 are in my heirarchy. I notice that when I click on them, they all have their own distinct positions. I need to have Object1's position in the Object1 Vector3 Varaible. and so on and so forth.

The snippet that I posted--the script is attached to each of my game objects.

avatar image lampshade · Jun 15, 2010 at 03:16 AM 0
Share

I don't know what to tag $$anonymous$$y Game Objects as, they are geometric planes, which never move.

avatar image lampshade · Jun 15, 2010 at 03:17 AM 0
Share

I am getting the position of one of the game objects, if I could get the rest without attached seperate script files, that'd be great. THat is my goal here, not using seperate script files to find positions of invidiudal game obejcts.

avatar image Adrian Love · Jun 15, 2010 at 03:48 AM 0
Share

I'm just curious as to why you'd like to store the same information twice in a single GameObject. Other scripts will be able to access the transform component of this game object. So if you were in another script you could just use "GameObject.Find("Object_1").transform.position;" and that would return the objects' position...

avatar image lampshade · Jun 15, 2010 at 03:58 AM 0
Share

All right! Thanks a lot, I didn't think about just accessing the position directly in the script that I needed it in, Duh!...Thanks! =)

Show more comments
avatar image
0

Answer by TSSTUDIOS · Feb 21, 2015 at 03:03 AM

here

if(star1position){transform.position = GameObject.Find("Star1Position").transform.position;}

in this case i got a bool but u can simply

transform.position = GameObject.Find("Star1Position").transform.position;

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

GUI Box not showing up after object clicked 1 Answer

How to add component to a child of gameobject 3 Answers

selecting and organising objects in editor 0 Answers

Deactivating/activating gameobjects on button press 1 Answer

how to make public variables unique to the gameobject it is attached to? 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