- Home /
to draw a cube on pressing the button
Im a beginner, i would like to draw a cube on pressing the button in scene01. Can you help me with the code? I already created a three buttons, Cube , sphere , prism. When i click on cube button , i want to draw the cube in the same scene. i created a c#file, which has the following code, using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour
{
private Button MyButton = null;
void OnDrawGizmosSelected()
{
Gizmos.color = new Color(1, 0, 0, 0.5F);
Gizmos.DrawCube(transform.position, new Vector3(1, 1, 1));
}
void onclick()
{
MyButton.onClick.AddListener(() => { OnDrawGizmosSelected(); });
}
}
Then after that i added the drawcube.cs file to the Cube inspector on click function. When i build the project and ran, there is nothing happening. can you please help.
This should help.
http://docs.unity3d.com/ScriptReference/Gizmos.html Gizmos are for scene view.
http://docs.unity3d.com/ScriptReference/UI.Button-onClick.html onClick
http://unity3d.com/learn/tutorials Tutorial Section
Your answer
Follow this Question
Related Questions
How can I draw 2D triangles in Unity 5? 0 Answers
Draw 4 points around object 1 Answer
Two OnClicks on one button. One doesnt work all the time. 2 Answers
triggering an animation on click? 1 Answer
Draw on Image 0 Answers