Search Unity

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,521
    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,521
    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,521
  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,521
  9. Wister1230

    Wister1230

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