unity- select 2D game object in mobile touch - unity3d

i want to know what is best way to select 2D object in unity mobile
for example i want to select one object and a menu show up for upgrade
i already searched but didnt find something good
if you write both code and good references would be nice

You can add a Button component to that object and add an OnClick() function call to it :
See a sample in Unity docs
or you can use Touches to have control over different phases :
See a sample in Unity Tutorials

You can add button instead of your GameObject and choose button sprite like as your GameObject's sprite then you will writing function to button to show your menu

Related

In unity how to make in-game menu?

I'm making a Unity2D mobile game but I'm stuck on making a menu. I want the in-game menu and if the player touches the screen or clicks the screen, the game will start and the menu will be have store, options but I don't know how to do it. I tried to do the same scene but this time when it goes to the next level, the menu disappears. I searched on the internet but couldn't find it. Thanks.
You should first create a UIManager script for yourself.
In this script, you must define 2D elements such as Text, Canvas, Panel and provide their functionality.
Then you can control these functions in your main manager (GameManager).
To put it simply, it takes almost a video tutorial to explain it.
Because this is not a simple code error question, man.

How do I implement a raycast / laserpointer to Oculus controller?

I want to implement a graphic raycaster/ laserpointer to the left Oculus controller, so I can interact with UI buttons in Unity.
I have seen a lot of tutorials etc. but nothing has helped.
I want a laserbeam or laserpointer/graphic raycast to shoot out from Oculus controller when a button os pressed on the controller. I need the laserbeam to interact with UI buttons in Unity.
You can use a normal raycast
I recomend you make this:
Create a script on your hand,and add a component called line renderer
In the script attach the lineRenderer component
make a simple raycast hit
get the position of the hit object
set the first position of the actual hand and the second to the hit object like this:
lineRenderer.SetPosition(0,transform.position);
lineRenderer.SetPosition(1,hitObject.transform.position);
And it draw a line from your hand to the hit object, remember to change the lineRender parameter to make a beautiful line
hope it helps
I created a project that uses unity's event system. It is a laser pointer which you can interact with unity's UI and 3d objects in the scene. If you want to check it out here's the link: https://github.com/balataca/oculus-laser-pointer

EventTrigger component only works with UI system?

I'm new to Unity and using 4.6 version.
I have a prefab which is just a sprite. And I instantiate three of them.
I want to receive touch and mouse events from those instances.
So, I added EventTrigger component to them from c# script, and added ClickEvent.
And I also added IPointerClickHandler and implement of it.
But it never gets any event. What am I missing?
Is TriggerSystem only works with UI system? Because I did not add any UI Pannel or UICanvas or etc. ( instead I added an empty object and added TriggerSystem component to it )
If this is not a good way to do, please give me a direction to start.
Thanks in advance.
Below is for Mobile devices.
If you want to do in game controls without UI you can use Input
This is Unity document.
It pointed TouchPhase and all of touch phases can find here.
Unity document has good example codes i think you should check it.
For GUI system to work there should also be an EventSystem object in your scene.
You can do it the easy way too, from the editor add a collider2d to the the sprite.
Write this to an script attach it the the gameObject.
void OnMouseDown() {
// do something
}
Unity also convert mouse event to touch events on touch systems so you may not need to worry about simple touch events.

Unable to use Unity UI elements on my android

I just created a very simple 3D game, and I used Unity UI for the first time.
Inside the game editor I can click the buttons and move the sliders.
I build the game for my android,and I can see all UI elements on my device but however, for some reason, I just can't use them.
Can you please help me and explain what am I doing wrong? Is it a bug?
I found the problem.
The Canvas element comes with "EventSystem" object. All I had to do is to check the CheckBox called "Allow Activation on Mobile device"...

How to create a menu form with different buttons from a unity sprite without using NGUI

I want to create a main menu in Unity3d for which I have taken a sprite as main menu window and many small sprites as buttons. I wish to write a script that I want to attach to my main menu and that will detect which button is clicked and what function to call. But I don't know how to do that. Can anybody help me?
I think the quickest option would be to display the sprites and add a "OnMouseDown()" script, you only need a collider on it.
More information: OnMouseDown()