Unity specific area touch input - unity3d

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

Related

How to check if player clicked on a specific layer?

I have a mobile game with a simple mechanic where player must touch screen to jump. Problem is, if player clicks pause button, character jumps as well. I need to prevent this.
I came up with an idea of creating a square without sprite renderer and cover the area that I want to prevent from click and simply give a layer to that square so I can control if player is not clicking that layer, then jump.
How do I achieve this? Any help would be appreciated.
Thanks a lot.

How to make a button inside scroll view interactable. Unity UI 2D

I have a scroll view and when I place buttons inside it they are not interactable how I can fix that?
I'm listing down common mistakes which can cause UI intractable issues in Unity:
Make sure you have a Game Object with an Event System and Standalone Input Module component attached to it in your Scene, You can create one from GameObject Menu > UI > Event System.
Screenshot showing the same
Make sure some UI element/Game Object not blocking your clicks(sometimes it happens we have a transparent image over our element which can block input).
Make sure there is a Graphics Raycaster component attached to the game object which contains a Canvas component if you want their child elements to receive input.
Make sure your button's Interactable property is set to true.
Make sure you set the Raycast Target property to true for your button's Image.
Is it in the contents box inside the scroll View? If not then put the game object in there

unity3d detect gameobject enters in main camera screen and leaves

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

unity2d button collider collide with border when character moves

I made a button that is clickable during the game playing. As I want the button have a fixed position in the main camera, I made both the main camera and the button children of the player gameObject so that the camera will follow the character while jumping or moving, everything works fine but there also a border colliders which will prevent the character moving out of the playing area. But then the collider of the button which was made intend to make the button clickable will also collide with the border which will prevent the character moving right forward. If we set the collider of the button a trigger, it seems that the button will be triggered wherever I click the mouse on the screen, that's not what I wanted.
I know maybe I could prevent this by checking if the collided object is the button or the character, but is there a better way to do that? Thanks.
For a 2D platform game, I would add a 2D user interface in a canvas over the "map" (the layer where you have the gameobjects like the character, platforms, enemies...). So the button will be always in the same place of the screen and will never collide with any gameobject of the game.
You make take some ideas from here: https://unity3d.com/learn/tutorials/topics/user-interface-ui/ui-events-and-event-triggers
Try use new UI in Unity may it fix your issue:
https://unity3d.com/learn/tutorials/topics/user-interface-ui/ui-button

simple UI menu and canvas for DK2

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).