unity 5 button not showing up in editor - c#

I'm trying to create a start menu for my unity 5.3.1 game by following this tutorial : https://www.youtube.com/watch?v=pT4uca2bSgc
I followed everything he said up to the part when he attached the script to the start button on the main menu screen. Here is a picture of my code and editor:
Any help is appreciated thanks.

You have attached that Title script to the "canvas" Canvas Game Object - not the "start1" Button Game Object.
In reality in doesn't matter, because you can tell your button to call any method on any game object when clicked.
To do that, select your button, for the OnClick event drag the Canvas game object, then from the drop down select the Title script and the startLevel() method.
Now when you click the button your level will load.

Related

Clicking anywhere triggers the button

In my scene, I have this set-up:
Game Controller
Level Controller
Main Camera
Event System
Canvas
Player
PlayerCanvas (Render Mode is World Space)
Button
I set the PlayerCanvas into the same width and height of the button. And both of them are just small. I put Debug.Log to check everytime I press the button. But somehow, it triggers the button even if I click way off the screen. Can help to explain why is this happening. Thanks!
Note: I'm trying to add a button beside the Player so that even if the Player moves, the button will just follow.
I think your hierarchy is wrong.
Try something like
Game Controller
Level Controller
Main Camera
Player
Event System
Canvas (Screen Space - Overlay)
Button
Not sure what Player is, but I'm sure on my hierarchy Event System and Canvas are on the same level. And every button is son of Canvas. Not sure you can make multiple Cavas (you should not need it anyway).

How to load prefab from folder only when player want?

I have a many prefabs in game but I want to load them only when player click button not on start runtime. I know there is only way to load prefabs from Resources folder but it gives me the problem the prefabs are loading all in same time at runtime start not when player click the button.
You can add the same function on OnClick event.
Click on Button component. there would be an OnClick event.
Click on +. Drag the gameobject which contains the method and drag that method on OnClickEvent.
Let me know if it helps.

Unity 5.4 Button auto-clicks

When I create a button in unity3d 5.4 the button just clicks automatic when i press play in the editor. I haven't been using unity before, so I can't say if it would happen in other versions.
First i create a script, then I attatch it to a empty gameobject. Then I press the little + sign on the OnClick() in the button properties, so I can add the gameobject with the script attached.
I have screenshots of button properties, eventSystem, Canvas, gameobject and the Script.
If anyone know what i have done wrong, please let me know. Thanks in advance.
The screenshots are in this post, since I cant post 5 images in stackoverflow:
http://forum.unity3d.com/threads/unity-5-4-button-auto-clicks.426526/
When you press play in editor, Button is NOT pressed at all. Its just that you have Debug.Log("Clicked!") in Start() method. Start() is called by Unity automatically when you run the application. It has nothing to do with button click. You need to register OnClick() listener method so it will be called when you press the button.
Have a look at this tutorial : https://unity3d.com/learn/tutorials/topics/user-interface-ui/ui-button
EDIT :
Please learn more about scripting here: https://unity3d.com/learn/tutorials/topics/scripting

Unity - change image onClick button (C#)

I make menu for my game (Android, C#) and i have simple problem. I want change image in button when the button is pressed. What is the best way currently? Not some preset way in Unity? Thanks
Use button animations. They can be auto generated. Change the sprite in the button press animation manually after generation.
Cost efficient way would be changing sprite object sprite field by getting the UI Image component in the button object from script.

Unity 5 does not create new scene

I'm newbie to Unity 5 and I have problem with creating new scenes. After creating a project ,I go to File->New Scene but the scene does not appear at all so I can't do anything with it ! Here's the image from what I see in Unity:
Your new scene is there. Your layout is likely messed up.
Click on the Default in the image above(where red arrow points to) then click Default. It should reset everything to normal. You can press Control + S to actually save the scene.
Hit Layout in the top right corner, select "2 by 3"
You will see your scene and game view quickly that way.
Have you enabled the scene view and switched to it?
Maybe you are viewing the game view. There is nothing in the scene so nothing will be displayed in game view.

Categories