Author Topic: Change UISprite size base on two gameObjects distance  (Read 2710 times)

0771

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Change UISprite size base on two gameObjects distance
« on: February 08, 2016, 06:06:19 AM »
I have two gameObject in front of the orthographic camera.
And the distance from gameObject1 and gameObject2 for instance
var distance = Vector2.Distance(gameObject1.transform.position, gameObject2.transform.position)
How do i make the sprite width equal to this distance ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Change UISprite size base on two gameObjects distance
« Reply #1 on: February 09, 2016, 02:44:06 AM »
Easiest way? Create a widget. Anchoring set to advanced. Left side anchored to one object, right side anchored to another.

0771

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Change UISprite size base on two gameObjects distance
« Reply #2 on: February 15, 2016, 09:57:19 PM »
Thank you for the answer,

But my sprite size is created randomly and i don't know how to get left and right position.
How to get the left position and right position of the sprite, so i can attach anchor base on
that positions.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Change UISprite size base on two gameObjects distance
« Reply #3 on: February 18, 2016, 06:46:46 PM »
I don't understand the question. Created randomly? Get position to attach anchor base? What?