I need help. When I click a Button, I want to create a new Button. My code, however, creates four Buttons. What should I do?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
public class AddButton : MonoBehaviour
{
public GameObject prefabButton;
public RectTransform ParentPanel;
public Button saveButton;
void Update()
{
if (Input.GetMouseButton(0))
{
// for (int i = 0; i < 2; i++)
{
GameObject button = (GameObject)Instantiate(prefabButton) as GameObject;
button.transform.SetParent(ParentPanel, false);
button.transform.localScale = new Vector3(1, 1, 1);
}
}
}
}