- Home /
How do i create an object with a GUI Button
Ok so i was wondering how do i take a GUI button and make it attach a gameobject to the mouse when the button is pressed. For example, there is a button, user presses it with the mouse and a cube is then attached to the mouse. The gameobject moves with the mouse until i click again. When you click again it places the gameobject in the world. How do u do that????? Please help.
Answer by NicoLocke · Jun 22, 2013 at 09:25 AM
These might be some use, let me know how you get on.
http://answers.unity3d.com/questions/391337/how-to-place-a-prefab-in-the-current-mouse-positio.html
http://answers.unity3d.com/questions/447953/create-a-primitive-placed-relative-to-camera-mouse.html
http://answers.unity3d.com/questions/406636/3d-object-attach-to-mouse-1.html
ok so i tried the first link since that is the only one in C#. And i ran into a snag and it is with the line GameObject newGameObject = newTransform as GameObject;
I get an error and the error is Error CS0039: Cannot convert type 'UnityEngine.Transform' to 'UnityEngine.GameObject' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion (CS0039) (Assembly-CSharp) Do you happen to have any idea what i can do to fix it
Your answer
Follow this Question
Related Questions
4.6 UI Image follow mouse position? 4 Answers
Knowing when a button is pressed, not released. 2 Answers
Disable Selection on Left button Mouse Click 3 Answers
How to prevent mouse from leaving area 0 Answers
Myst-style UI for exploration game? 2 Answers