- Home /
 
               Question by 
               uanmanarmy · May 22, 2015 at 10:15 PM · 
                animationbuttonpositioncoroutinesrecttransform  
              
 
              Make position of Buttons Elastic.
Hey guys Im trying to make a circular menu system and I made them to go to the desire position but I want a little bit more lets say animation effects. Here is what I want to get.

Code
 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 public class PieMenu : MonoBehaviour {
 
     public int numPoints = 20;                       
     public Vector3 centerPos = new Vector3(0,0,32);   
     public Button[] pieObj;
     public float radiusX,radiusY;                 
     public float smoothing = 5.0f;
     public bool isCircular = false;                 
     public bool vertical = true;                  
     Vector3 pointPos;                        
 
     void Start()
     {
         for(int i = 0; i < numPoints; i++)
         {
             pieObj[i].GetComponent<RectTransform>().localScale = Vector3.zero;
         }
     }
     public void OnClickCenter()
     {
         if(isCircular){
             radiusY = radiusX;
         }
         StartCoroutine (Move ());
     }
      
 
     IEnumerator Move()
     {
         for(int i = 0; i<numPoints;i++){
             //multiply 'i' by '1.0f' to ensure the result is a fraction
             float pointNum = (i*1.0f)/numPoints;
             
             //angle along the unit circle for placing points
             float angle = pointNum*Mathf.PI*2;
             
             float x = Mathf.Sin (angle)*radiusX;
             float y = Mathf.Cos (angle)*radiusY;
             
             //position for the point prefab
             if(vertical)
                 pointPos = new Vector3(x, y)+centerPos;
             else if (!vertical){
                 pointPos = new Vector3(x, 0, y)+centerPos;
             }
             Debug.Log(pointPos);
             Debug.Log(i);
             
             //place the prefab at given position
             while(Vector3.Distance(pieObj[i].GetComponent<RectTransform>().localPosition, pointPos)>10f)
             {
                 pieObj[i].GetComponent<RectTransform>().localPosition = Vector3.Lerp(pieObj[i].GetComponent<RectTransform>().localPosition, pointPos, smoothing * Time.deltaTime);
                 pieObj[i].GetComponent<RectTransform>().localScale = Vector3.Slerp(pieObj[i].GetComponent<RectTransform>().localScale, Vector3.one, smoothing * Time.deltaTime);
                 yield return null;
             }
 
 
             //yield return new WaitForSeconds(2f);
             print ("MyCorutine is now Finnished");
         }
     }
 }
 
I want to make the finnised position a little bit more like elastic effects. AnyIdeeas?
 
                 
                screenshot-9.png 
                (25.4 kB) 
               
 
              
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                