How to show cursor in Unity "Play mode" - c#

I am new to Unity, and have created a simple start menu with a play button that will load a game scene. However, when I click "Play" in Unity to test my game, I do not have a cursor. I have to hit escape for my cursor to appear. Do I need to create a script file to make my cursor visible, or how do I change this? I am unable to find anything in Unity forums. Googling the topic retrieves many "How to hide cursor" threads.
I have tried adding an empty object and adding a c# script to it that contains the following but I think I am missing a step?
public class CursorBehavior : MonoBehaviour {
// Use this for initialization
void Start () {
Cursor.visible=true;
}
}

I think this can help you.
Cursor.visible

Related

Button in unity doesn't work, how can i fix it?

I am new to unity and I am still learning. I am making a game and its going great but I have a problem with a Quit button.
It doesn't use the script attached to the On Click () section in the button menu.
There's an EventSystem in the Hierarchy, the Force Module Active is checked, the button is a child to a canvas. I don't know why the button isn't working
Here is the code in the script attached to On Click ()
public void Quit()
{
Debug.Log ("YES IT WORKS");
Application.Quit ();
}
I want the program to close when the button is pressed but when the button is pressed nothing happens!
The function is not being called when the button is pressed which means that you have not selected the function in the onClick settings. To do this, ensure that the script is attached to the button and then dragged into the onClick box of the button in the inspector. Next, click on the dropdown and hover over the name of the attached script and select the function that you want to call.
Solution
Instead of using Application.Quit() try to shift the your working scene to the home screen .Your every game should start and end at the same level which is also known as the main scene of the the game. Secondly before shifting to other scene you should destroy your player and save the scores in the player pref .
Player Pref:
The library which helps the user to store the data and show them on the main screen , Hence the use of database will not be there in order to save the data for the small games . You are beginner so you should look at these all thing on You tube or the unity website documentation available on its website
Are you in the Editor?
Application.Quit() only works when you build the application (for PC and Android. It should not work on iOS, and even if it works it should display as a crash so it's not good).

I can't assign scripts to buttons in UNITY?

I just started exploring Unity and I'm making a game in UNITY 2D.
I decided to start with a simple menu screen to get used to UNITY.
I made the menu and moved on to programming the buttons.
However when I drag the script (or the game object holding the script) in to the button on click section and try and select my function it does not show up.
My unity window
Manager in the button on click script.
My code in C# (this is my first time using c#)
what I want to know is: have I done something wrong; doe unity work differently to how I understand it; is unity doing something weird; how do I fix it.
(appologies for the weird post layout I don't know why it did that).
Just insert a ; at the end of your code and you should be fine. You should notice that the compiler is complaining about the missing semicolon. Also, make sure to attach your script to the _Manager GameObject.
You need to :
add a semi colon to the end of the line in the Buttons class
Add Buttons Class to the _Manager gameobject in the scene

Vuforia + Unity : Instantiate model in AR when UI Button pressed

I know this is a really simple question but I can't figure out how to archive this:
I have a UI button in my scene and I want Vuforia to instantiate one AR Model ONLY when I press a button.
Following the tutorial on the net I was able to instantiate a model on the screen when I touch it but I need to know how to set up Vuforia for archive the same result only when I press a button.
I have to disable the "Anchor Input Listener Behaviour"?
And then?
I want to call for the PositionContentAtPlaneAnchor but I can't figure out how to call it in the right way in the OnClick field of the button. I need to make a custom script for this?
Thanks for any answer.
Ok, sorry for the delay.
I deduce that you are working with the ground plane, if you have the Ground Plane Stage and the Plane Finder in the scene and works, we're at a good point.
Now, you must only add a button to the scene and into the script add something like this:
public PlaneFinderBehaviour plane;
void Start()
{
...
buttonOnTheScene.onClick.AddListener(TaskOnClick);
...
}
void TaskOnClick()
{
Vector2 aPosition = new Vector2(0,0);
...
plane.PerformHitTest(aPosition);
}
What does it mean?
First of all, you must move the Plane Finder from Hierarchy to the script variable, so we have a reference to the plane into the script.
Then when you click (or tap) on the button you simulate the click (or tap) on the display with the PerformHitTest.
If you're wondering why my question in the comment, it's because the Plane Finder Behaviour Script has two modes type: Interactive and Automatic. The Interactive intercept the tap on the display and shows the object (on the ground plane) in the exact position of the tap, the automatic shows the object in the center of the plane.
So if you want the object in an exact position you can pass a Vector2 position in the PerformHitTest and if you want to show an object programmatically or do something when it shows the object you can call a custom method OnInteractiveHitTest.
That's all.

Play animation once?

I've made a simple animation for my dishwashing machine in 3dsmax. I imported the object as an fbx file into Unity. The animation is called "openandclose". The animation itself opens and closes the machine.
However I can't seem to find a way to trigger the animation to happen once at the click of a button. How can I do this?
Unity has a great documentation regarding every core function including animations. Check this link out: http://docs.unity3d.com/462/Documentation/ScriptReference/Animation.Play.html
and to get the button pressed:
http://docs.unity3d.com/462/Documentation/ScriptReference/Input.GetKeyDown.html
combined it would be something like this i guess:
void Update() {
if (Input.GetKeyDown("e"))
animation.Play("openandclose");
}

Unity; animation on prefab

Tried to find this kind of problem around the net but failed so...
Here's the thing - I have a prefab gameobject that is to represent a unit, portrait more specifically. It has several scripts attached and an Animation component with two animations: Static and Selected.
The prefab is instantiated, moved freely and, after placing, it can be clicked to select it, which should, aside from executing a bit of code, start the Selected animation.
Using this code:
void OnMouseDown(){
//
//Some inside stuff
//
if (this.GetComponent<UnitHandling> ().thisUnit.Selected)
this.animation.Play("Selected");
if(this.animation.IsPlaying ("Selected"))
Debug.Log("Animation of selection is playing");
}
I checked that the animation seems to be playing (at least the Debug message is showing) but I see no animation... What am I doing wrong?
Try making an animation state using mechanim, and play it using this:
GetComponent<Animator>().CrossFade("Selected", 0);
https://docs.unity3d.com/Documentation/ScriptReference/Animator.CrossFade.html
https://docs.unity3d.com/Documentation/Manual/MecanimAnimationSystem.html

Categories

Resources