Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Get position on y axsis

Discussion in 'Getting Started' started by hrohibil, Apr 22, 2021.

  1. hrohibil

    hrohibil

    Joined:
    Apr 17, 2021
    Posts:
    280
    Hello

    noob question here.


    I have a cube. I want to output/print to the console whenever my cube moves above a specific value in the y axis (up). So basically how do I detect position.


    Br Hamid
     
  2. jbnlwilliams1

    jbnlwilliams1

    Joined:
    May 21, 2019
    Posts:
    267
    In your update function, on the cube, just check the gameObject.transform.position.y, if it is greater than the y value you are checking for output to the console...
     
    JoeStrout likes this.
  3. hrohibil

    hrohibil

    Joined:
    Apr 17, 2021
    Posts:
    280
    Thank you.

    so could I write this in the update

    if ( gameObject.transform.position.y > 20)
    {
    print(“Cube is above 20 units on y”);
    }
     
  4. jbnlwilliams1

    jbnlwilliams1

    Joined:
    May 21, 2019
    Posts:
    267
    Yes, but replace print... with Debug.Log("Cube is above 20 units on y”);