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
-1
Question by Midnigh · Feb 24, 2014 at 11:33 PM · positiongame object

if game object is located at...

Is it possible to do this?

I can't seem to find out...

     if(gameobject.position == (0,0,0))
 {
     debug.log("test")
 
 }

or something like that anyways?

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
0
Best Answer

Answer by robertbu · Feb 24, 2014 at 11:37 PM

It would be like this:

 if(gameObject.transform.position == Vector3(0,0,0))
 {
     debug.log("test")
 }

In C# you would have to add 'new' in front of the Vector3(). Note that in programming it is usually not a good thing to directly compare floating point numbers (and a the x, y, and z components of a Vector3 are floating point numbers). A direct comparison of Vector3s works in Unity because under the hood Unity is checking to see if the two values are within a small threshold distance from each other. This makes a lot of code work well, but you will not necessarily have exactly the same values. FYI: Vector3.zero is shorthand for Vector3(0.0, 0.0, 0.0).

Comment
Add comment · Show 5 · 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 Midnigh · Feb 24, 2014 at 11:42 PM 0
Share

the issue is that "position" isn't a member of unitygameobject so it doesn't work. I was wondering if there is something like that I could use to check if a gameobject was at a specific position.

Also tried...

 if (key.transform.Translate(0,6,0) == true)
 {
     Debug.Log("test");
 }

but it doesn't seem to work either...

Also doesn't seem to work...

 if(key.transform.Translate == Vector3(0,0,0) == true)
     {
         Debug.Log("test");
     }
avatar image Kiloblargh · Feb 25, 2014 at 01:02 AM 0
Share

"gameObject.transform" is not the same thing as "`gameObject`," and "`transform.position`" (a property / variable) is not the same thing as "`transform.Translate`". (a function / method) Those mean totally different things and are not interchangeable.

Similarly, using == twice in an if statement like you did shows that you don't understand what it means either. Actually I don't think you understand the syntax of C# or JS at all. That's ok, because everyone starts there. But rather than just guessing and hoping it will work out (it never will), you have to look up everything and read the reference manual very, very carefully before every word or symbol you type.

avatar image Kiloblargh · Feb 25, 2014 at 01:12 AM 0
Share

Also, what you're trying to do isn't something you should be doing, as robertbu suggested. The only reason a gameObject would be at 0,0,0 is because it was instantiated there and never moved. If there are a limited number of places it can be, you can store which set position as an integer (which can also be its index in your spawn point array) at the same time you originally placed it there. Or if it is moveable and you want to see if has been placed in a certain area, use a trigger collider.

avatar image robertbu · Feb 25, 2014 at 01:29 AM 0
Share

Sorry, my answer had a problem. The above code should now compile and work.

avatar image Midnigh · Feb 25, 2014 at 02:37 AM 0
Share

Thanks @robertbu I am new (though I think you already know that). I got the script finally working. It seems that I messed up on one of my other scripts and things weren't working together correctly. However now thanks your guys assistance I manage to get the script fixed and functioning how I had hoped ^^

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

20 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

Related Questions

Issue's With Positioning 0 Answers

Game Object to Transform Position 1 Answer

Camera rotation around player while following. 6 Answers

Find a GameObject exactly in position Vector3(1,2,3)? 3 Answers

Camera movement 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