Is it Unity Interaction System?
Hey everyone,
I'm working on my 2D game using Unity as my game egnine and I got stuck with something that might seem like a stupid question. ๐
But I need to know how to make certain objects in a game checkable by the player. Meaning the play can click on the object such as an image and it enlarges and players can flip/rotate, zoom in/out during playtime.
For example, a picture on the wall, once clicked on becomes full screen.
I tried to search for the interaction system in Unity but didn't find much helpful tips. ๐
About this post
- Posted
- Archived
- Score
- 1 ยท 60% up
- Kind
- Text
- ID
- 160spjo
2 comments
You'll have to create an interaction component class and interface IInteractable.
In the interface create a method called OnInteraction() and implement this interface on the needed classes.
On the interaction component create a method Interact and have it shoot a raycast when you press a certain button in the direction you're looking, with the TryGetComponent method on the hit variable of the raycast look for an IInteractable interface, if found, execute the OnInteraction() method.
This os as far as i can help from mobile. Look into the documentation of Physics2D.Raycast and TryGetComponent if needed.
Best of luck!
How about OnMouseDown? https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseDown.html