Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

GameObject Distance Question.

Discussion in 'Scripting' started by Wister1230, Jun 30, 2015.

  1. Wister1230

    Wister1230

    Joined:
    Jun 6, 2015
    Posts:
    50
    Hello,
    How can I do that the object distance can be from 0f till 3f in the Z pos?

    This Distance in Function...
    Code (CSharp):
    1. Vector3 MousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Distance);
    Thanks all for help!
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,386
    Code (csharp):
    1. Vector3 MousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Mathf.Clamp(Distance, 0f, 3f));
     
  3. Wister1230

    Wister1230

    Joined:
    Jun 6, 2015
    Posts:
    50
    What number I have to set the distance variable? And My blocks goes under the terrian map what should i do?
     
  4. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,386
    Please explain what you are trying to do.
     
  5. Wister1230

    Wister1230

    Joined:
    Jun 6, 2015
    Posts:
    50
    I`m trying to make the GameObject able to go far from me and close to me (far = 3f and 0f = close.)
     
  6. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,386
  7. Wister1230

    Wister1230

    Joined:
    Jun 6, 2015
    Posts:
    50
    Vector3 PlacingObjectPosition = Camera.main.ScreenToWorldPoint(MousePosition);
    PlacingObject.transform.position = PlacingObjectPosition;
     
  8. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,386
  9. Wister1230

    Wister1230

    Joined:
    Jun 6, 2015
    Posts:
    50
    Why yay?