What's the best way to trigger an animation from the input of another object? - unity3d

I'm new to unity and c#.
When i air tap on the left sphere, the plane and the right sphere should appear.
I figured that an OnPointerClicked event on the left sphere the animation of the plane and right sphere triggers (with an if/else statement).
Is this the way to go?
If so, how do i do that?
Or is there an easier method?
Thats the script of the left sphere:

Read this: IPointerClickHandler.OnPointerClick
You need to implement the interface, i.e. IPointerClickHandler in your MonoBehaviour class. When you click on the object in game, it will send a click event to EventSystem, which triggers the function body you have in your OnPointerClick method.
So as the doc mentioned, also make sure you have an EventSyetem (an empty game object with the script attached, or attach the component to your main camera).

Related

World space button click event to take priority over the collider's click event it's inside?

Short story:
I have a button on a world space canvas with a click event handler. This is inside (in 3d space not parenting) of a 3d collider with it's own click event.
The collider always gets the click event as expected as it's nearer the camera.
I want the button to get the event.
Long Story:
I have a person mesh with a collider. You can click on them and the OnPointerClick triggers to do something.
I have a button that sits in a world space canvas which itself is located just above the mesh and is pointed towards the orthographic camera. You click on the coin and the OnClick event triggers to do something else.
Both events work as expected until the coin is inside the mesh's collider (which it is a lot of the time). At which point it's ONLY the mesh collider's OnPointerClick event triggers, not the button.
However, I ALWAYS want the button to take priority over the collider, and any other collider. This is easier when the canvas is screen space, but it's not (with reason).
How do I do this?
NOTES:
The button never gets the onclick event, so any filtering on the containing collider won't help
I've fiddled with the world space canvas and camera ray filtering settings to no effect.
The coin has to be a world space canvas for automatic tracking and because I use text too
IsPointerOverGameObject doesn't help as it's true for any collider, not just UI elements. Not to mention it wont stop the collider consuming the click anyway. A custom version of this that works via a layer wont help either, because again the OnPointerClick on the collider GO stil consumes the click.
I don't want either event to have to do any event filtering & passing on if possible, they should be atomic. Any filtering should be via setting properties in objects and inherent functionality of Unity if possible
Just to reiterate, writing a function to find all objects in the ray and then selecting ones that are on the UI layer first wont help. Because that does not change the fact that the collider still is the only thing that gets the event, which then you'd have to manually propagate down to the button.. which I don't want to do.
I've been able to fix this by putting the button's world space canvas on a sorting layer of 1. That way, even if it's behind colliders, it will register first.
Nice and clear solution that I was hoping would exist.

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

Unity: Drag on Screen and instantiate game object

How can I continuously instantiate Game objects by dragging on screen with unity and making the game object to follow the direction of the dragging?
For example: Drag right instantiates right, Drag up instantiates up or drag upwards at a certain angle and instantiates accordingly.
I don't know what you have done so far or how good you are in programming, but the basic principle would be
Create a DragInstantiate Script, which you put on a GameObject on your Scene, but not the one you want to Instantiate.
In the Update Method of this Script you have to check, if the left mouse button is pressed down. https://docs.unity3d.com/ScriptReference/Input.GetButtonDown.html
When you registered the click you have to save the position of the click. https://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html
The next step is to check when the left mouse button is released and again save the position. https://docs.unity3d.com/ScriptReference/Input.GetButtonUp.html
From these two positions you can really easy calculate the direction, in which the object should move. https://docs.unity3d.com/Manual/DirectionDistanceFromOneObjectToAnother.html
The last thing is to instantiate the object and set it's moving direction. https://docs.unity3d.com/Manual/InstantiatingPrefabs.html

unity | disable eventsystem module input for one gameobject

I have a eventsystem with 2 inputmodules (gaze (for cardboard) and touch). The gazeinput is above de touchinput, so that is going to be used by unity as main inputmodule. Now i have 1 object that i want to trigger on touchinput, but that is not working because of the gazeinput. So my question is if it is possible to disable the gazeinput just for this 1 gameobject?
EDIT: the object is a menu button, located in the bottom-right corner. It moves with the camera.
thanks
use raycast. when your camera is seeing the gameobject on which you want to use the touch input. detect that the user is looking at the camera via raycast.
Attach a script (to the camera or an empty gameobject) that has the reference of both the input modules
When the player looks at the object(detected through raycast) in which you want to use the touch input. Simply disable the gazeinput.
And when the player looks away from that gameObject enable the gazeinput

how to add frictionless effect to an object on a plane

I'm new to Unity and the is working on a personal project. In the following picture, you can see a blue plane in the middle, I want to use it as a ice plane and there should be no friction when user is walking on it. In another way, if I press 'w', the object should move forward until it hits an object. I know there's a built-in function called physic material, but it works only when the plane is tilt at some angle so that the object will slide down from the top to the bottom, but if the plane is placed in a horizontal level it will not work. Anybody has any suggestions for it, thanks.
Answering from my phone and off the top of my head, but look at using input.getaxisraw() to get your direction data then add forces. use triggers to stop the movement when you reach a trigger on another object. There were some good tutorials on Collisions and triggers on unity tutorials. To elaborate more, you can add colliders to the objects that you want your player object to interact with physically. So for your player object you can add code like:
OnTriggerEnter(collider c) {
// stop movement
}