Advertisement
Muk99

Untitled

Nov 12th, 2015
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1.  
  2.         distance1 = Vector2.Distance(sr.localPosition, new Vector2(510, -78.46f));
  3.         distance2 = Vector2.Distance(sr.localPosition, new Vector2(0, -78.46f));
  4.         distance3 = Vector2.Distance(sr.localPosition, new Vector2(-510, -78.46f));
  5.  
  6.         var distance = Mathf.Min(distance1, distance2, distance3); //Retorna a menor distancia
  7.         var desiredPosition = Vector3.zero;
  8.  
  9.         if(distance == distance1)
  10.             desiredPosition = new Vector2(510f, -78.46f);
  11.         else if(distance == distance2)
  12.             desiredPosition = new Vector2(0f, -78.46f);
  13.         else if(distance == distance3)
  14.             desiredPosition = new Vector2(-510f, -78.46f);
  15.  
  16.         sr.position = Vector3.Lerp(sr.position, desiredPosition, 2f * Time.deltaTime);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement