I created prefab via code, and then i trying to change position of this button. I add this script to the button
public class buttonClick : MonoBehaviour
{
public System.Action Clicked;
public Vector3 indent;
void OnClick()
{
Debug.Log("Super Effect!");
Clicked();
}
// I invoked this method from ButtonsManager
public void Init(Vector3 indent, System.Action action)
{
this.indent = indent;
this.Clicked = action;
StartCoroutine(wait(0));
}
// translation works only in Coroutine
IEnumerator wait(float waitTime)
{
yield return new WaitForSeconds
(waitTime
); transform.localPosition += this.indent;
}
void OnEnable()
{
Debug.Log("OnEnable" );
}
}
transform.localPosition changes take effect only after this frame. Simple transform.localPosition += this.indent; without StartCouroutine() doesn't effect on button position! I guess this is because of NGUI change this position in this frame.
So how should i properly change button position right after initialization!