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 /
This question was closed Mar 18, 2015 at 01:41 PM by Baste for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Zaineph · Mar 18, 2015 at 11:51 AM · positionobject

How to check the position of an object

Hi all,

I am trying to test if an object has fallen below a certain point on the Y vector and if so then I will run another function.

I'm just not sure how I can do an 'if' function to access the Y value in Vector3.

I was thinking it would look something like this:

 if (Vector3(x,y<1.5,0)
    {
        anotherfunction()
    }

I'm pretty certain that this won't work and that there is more to it, but I was hoping someone could point me in the right direction.

Thank

Comment
Add comment · Show 4
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 fffMalzbier · Mar 18, 2015 at 08:52 AM 1
Share

Looks like you need a refresh in how does "if statements" works http://unity3d.com/learn/tutorials/modules/beginner/scripting/if-statements

avatar image Zaineph · Mar 18, 2015 at 10:19 AM 1
Share

Ok i've looked into it a bit further I think that the below should work

 if (transform.position.y < 1.5)
    {
        anotherfunction();
    }
 else
    {
        //do nothing
    }
 

if I put this in the object's script then this should work right? or at least it seems right to me.

Basically when the object falls below the y value of 1.5 I what the other function to run.

I think it was simpler than I was trying to make it. I'll try it out when I get home.

Sorry for being a noob.

avatar image Firelight · Mar 18, 2015 at 12:36 PM 1
Share

yes, you are right. Just as a note, when using floats use the :1.5f notation like this :

  if (transform.position.y < 1.5f)

or else you risk that your values are casted to int

avatar image Baste · Mar 18, 2015 at 01:41 PM 0
Share

values being cast to int isn't a problem, this is safe:

 float x = 15;

What is a problem is that when you write "1.5", that's a double, not a float, and your stuff won't compile.

Anyways, the question is resolved, closing.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to render object in front of other object no matter position? 1 Answer

The appearance of some prefab appears somewhere else but their collider stays in the good place, that to make? 0 Answers

Spawning pre-selected objects randomly at fixed locations (2D game, #C) 0 Answers

Object changes its positions for no reason 1 Answer

Object isnt where its supposed to be when selected 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