i want to make an area in my game where i can get touch inputs from the player.
Now i get touch from all the way of the screen.
strong textI want to get from the buttom of the screen or so.
You can make an invisible UI element or GameObject and on there check if it was clicked or not. You can do this with either https://docs.unity3d.com/2018.1/Documentation/ScriptReference/EventSystems.IPointerClickHandler.html or https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseDown.html
I'm looking for events or a code that will give me information that gameobject entered in the main camera screen and then leaves the screen so i can destroy it.
What i'm doing is a top down game which is moving forward all the time... some objects are spawned far away so i want them to move when they enter in the game screen and after leaving the screen destroy them.
i tried this event but it's triggered before game object enters in the screen... i saw some comments that rendering engine is triggering this event for shadow rendering bla bla...
https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnBecameVisible.html
On top of OnBecomeVisible you also have other options such as OnWillRenderObject, Renderer.isVisible
You can also calculate whether an object's bounding box falls within the camera's view frustum, using GeometryUtility.TestPlanesAABB
I have made a simple 3D game in Unity and for the most part everything works, but when my player dies the mouse is not visible on the death screen.
I have two other scenes with what looks like to me the same exact settings, yet the mouse on those is visible.
Try to check your script. search for Cursor.visible
https://docs.unity3d.com/ScriptReference/Cursor-visible.html
I am using Unity 5.1.2p3 with DK2 SDK 0.6.0.1 and I understand from this post that Screen Space - Overlay is not supported in Unity VR. It is recommended to use Screen Space - Camera (which in my case does not work) or World Space (which I am using now) but I need someone to help me understand how I get simple menu with buttons and toggles to show as a still image and how I can make selections and button presses with my mouse cursor.
I have created a menu for my app, with 4 toggles and 1 button. When I check the Virtual Reality Supported option with the Oculus being in Direct Mode and Canvas being in World Space, I can see it in VR, but I cannot see/find my mouse cursor to tick one of the toggles.
When I take off the headset, on my monitor's Game View tab, I can see and even use the mouse and select a toggle. Obviously, I have to keep the headset steady, so in my Game View, things do not shake!
Another thing I notice is that the VR camera is the same as the Main Camera in the Unity Hierarchy, but when I take off the headset and move it around, the position of the camera does not change, only looking up and down and around is reflected.
How do I simply do a static menu like a 2D surface that does not move in VR and a user can use button presses and muse clicks with the headset on? What settings are required for this way of doing UI and canvas stuff? There are 2 attachments, showing my current settings...
Are you specifically wanting to use the mouse? If you look through a blog entry I wrote below, it will show you how to use Gaze looking to trigger menu buttons:
http://talesfromtherift.com/vr-gaze-input/
You can achieve this by some code I list there that raycasts from the center of the screen and if it hits any UI, it will trigger the correct events and make it clickable by button (or by time).
I have a game that I developed, and there are three scenes: the pause menu, the home screen menu, and the gameplay itself. During the gameplay, when the game is paused, it brings up the pause scene with:
[[CCDirector sharedDirector] pushScene:[PauseScene node]];
From the pause scene, there are three options: restart, resume, home menu. When clicking on resume it just pops the pause scene and goes back to the game scene to resume gameplay. When clicking on the home menu it keeps the gameplay scene in the background, and from the home menu screen, the gameplay is still running. So far, after much research, I have not been able to find a way to popScene (kick it out of the RAM pretty much) the gameplay scene from any scene but the gameplay scene. From the pause screen, I can use:
[[CCDirector sharedDirector] popScene];
to get rid of the pause scene, and if I run that code from a method on the gameplay scene, I can get rid of that instance of gameplay, but I need a way to popScene the gameplay node that is running in the background from the pause node. Overall, the basic question is: How can I pop a specific scene in Cocos2d from another scene?
There are two main features to change scenes in Cocos2d: pushScene/popScene and replaceScene.
The first is pushScene:
(void) pushScene: (CCScene *) scene
Suspends the execution of the running scene, pushing it on the stack
of suspended scenes. The new scene will be executed. Try to avoid big
stacks of pushed scenes to reduce memory allocation. ONLY call it if
there is a running scene.
This function utilizes a stack . It stores all the scenes in a Last In-First Out (LIFO) data structure. Basically it overlays the scenes and removes them in the reverse order of which they came. This is likely what you want to "push" (or bring up) the pause menu, and "pop" (remove) the pause scene back off to then resume gameplay.
To go back a layer, you simply call popScene:
(void) popScene
Pops out a scene from the queue. This scene will replace the running
one. The running scene will be deleted. If there are no more scenes in
the stack the execution is terminated. ONLY call it if there is a
running scene.
2.The other option, which I believe you will want, is replaceScene. This stops a currently running scene and replaces it with a completely new one. This is likely what you want for ending games or transitioning from the original main menu to the gameplay for the first time:
(void) replaceScene: (CCScene *) scene
Replaces the running scene with a new one. The running scene is
terminated. ONLY call it if there is a running scene
*Keep in mind: Use pushScene sparingly. It stores all of the scenes in memory so that they can later be popped of the stack. So don't store too many scenes and forget about them.
**Source: cocos2D website
EDIT 1:
You have a few options. Remember that replaceScene only replaces the currently running scene and is usually what you want to use. It does not "clear" the entire scene stack, so often you rarely want to use pushScene/popScene. In my demo below, I show you the issues with both. I do, however, try to conserve memory by when possible.
Using push/popScene:
1.Start running with the Home Screen.
2.When the user clicks "Play" button, use replaceScene to stop the Home Screen scene and start running the Game Play scene (keep in mind, Home Screen will no longer be running or saved anywhere in memory. if it has to remember any information, then save it to the stack with pushScene. The reason I do this is because the Home Screen will likely be the same each time and needs not continue to run while we play).
3.The user can now play for a bit. Then they want to pause for a bathroom break. They click a "Pause" button. Then use pushScene to save the current state of Game Play scene and begin running the Pause Menu scene. (Game Play is "paused" so to speak).
Your stack now looks like this:
//Bottom ----------------------> Top
[Game Play scene], [Pause Menu Scene]
4.After pausing for a bit, they could use pushScene to remove Pause Menu Scene from memory, and load the Game Play scene that is "paused" and resume play immediately.
The problem then becomes, well, what if you wanted to go from pause -> main menu. If you just used replaceScene on the Pause Menu, then the old game would linger in memory. You would need to find a way to purge that old Game Play scene.
The other option would have to be keeping Home Screen around by keeping it on the stack with a pushScene and then popping twice. This often causes "jumpy" transitions from my experience.
The preferred approach tends to be: create a Singleton Class and have that save the memory while you pause. (A Singleton Class is just a class that only ever has one instance. It is basically our "current game state" data. I recommend this tutorial.)
Using Replace Scene:
1.Start running with the Home Screen.
2.When the user clicks "Play" button, use replaceScene to stop the Home Screen scene and start running the Game Play scene (keep in mind, Home Screen will no longer be running or saved anywhere in memory. if it has to remember any information, then have a section of the Singleton Class for Home Screen data).
3.The user can now play for a bit. Then they want to pause for a bathroom break. They click a "Pause" button. Immediately "pause" your game and save all necessary sprites, game logic, etc to the Singleton Class, and then use replaceScene to quit from the Game Play scene and load Pause Scene. Then depending on their choice, you either continue play (step 4), or go to the Home Screen(step 5)
4.Reload everything necessary to render the game from the Singleton Class and replaceScene to quit from the Pause Menu and load up Game Play scene.
5.Use replaceScene to quit from the Pause Menu and load up the Home Screen.