- Home /
Question by
galaboy · Mar 18, 2015 at 07:16 AM ·
uibuttonscriptingbasics
transforming UI button dynamically
hi, am in a situation where i have to spawn five buttons one by one below. i wrote a script which instantiates the buttons, but at the same positions. need help on this.
using UnityEngine;
using System.Collections;
public class eventManager : MonoBehaviour {
public GameObject button;
bool canInstantiate = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(canInstantiate == true)
buttonCreation ();
}
void buttonCreation()
{
Vector3 transformPosition = new Vector3 (0.0f, 2.0f, 0.0f);
for(int i = 1; i <= 5; i++)
{
Instantiate (button, transform.position + transformPosition ,transform.rotation);
}
canInstantiate = false;
print (canInstantiate);
}
}
Comment
UI 4.6 elements are positioned by Rect Transform and not Transform.
If you want to arrange UI dynamically. You should google Unity layout
Your answer
Follow this Question
Related Questions
Unity UI dynamic Buttons 4 Answers
change UI button image .. 3 Answers
Initialize button state icon by script 1 Answer
How to click on irregular buttons in new ui 4 Answers
Unity UI button does not detect click 2 Answers