- Home /
UI Button Trigger?
I'm using this code to make cubes fall from the top of my screen and I want to be able to do it when I click on my UI button that I have created. I just can't get it to work 100%.
Any help is appreciated!
using UnityEngine;
using System.Collections;
public class ButtonPush : MonoBehaviour {
public float delay = 0.1f;
public GameObject Cube;
// Update is called once per frame
void Update () {
Instantiate(Cube,new Vector3(Random.Range(-10,10),10,0),Quaternion.identity);
}
}
Answer by DoTA_KAMIKADzE · May 14, 2015 at 09:50 PM
You should move your Instantiate code line from Update function to function that will be called on your UI button click. You can do that in various ways, using Inspector which is greatly documented HERE or just code (for examples of which check my answer THERE).
At first I didn't quite understand what I was doing wrong because I had seen that video before and had gone through the process, but then I realized that I just needed to remove Update and add Public. :P Thanks for your help!
Your answer
Follow this Question
Related Questions
Draw a line to a new pontential character position/target 1 Answer
Can't add reference resolution on Canvas 1 Answer
need some help with this things 0 Answers
Fading Out UI On Play 1 Answer