Teaching materials for the school of programming. Part 12
Previous tutorials can be found here:
This material has two parts:
In the first, we will consider creating convenient sticks suitable for any screen resolution and any diagonal.
Let's get acquainted with the use of the Event System in the context of working with the UI and the implementation of custom handling of the reaction to the mouse / touchpad pointer.
Next, let's move on to the second, where we will create a script that implements access to other objects through the Event System.
Along the way, let's try our hand at working with static variables to implement a convenient implementation of modules in the project, and learn about the global and local coordinates of RectTransform.
Both parts of the lesson are a continuation of the Liquid Character project.
You can traditionally download all materials here . The folder contains files for both parts.
Execution order
Let's create a new panel with the following parameters:
Panel - responsible for the active zone for clicks. The area on which the stick will work depends on its size.
2 Image - Joy Mushroom Joy โ , Mushroom โ .
:
, .
. . ( , - ):
:
using UnityEngine.EventSystems;
OnPointerDown OnPointerUp. : IpointerDownHandler IpointerUpHandler.
( ) private PointerEventData eventData;
OnPointerDown eventData.
eventData Update().
, , , OnScreen. , true, Joy Joy Mushroom .
OnPointerUp Joy Mushroom OnScreen false.
Update().
Mushroom .
: , .
/ โ . . .
, , GetAxis Input.GetAxis("Horizontal") CustomStick.horizontal
.
, , , , EventTrigger.
. , , Canvas .
, - .
.
Goo ( ), . , .
. :
, , . .
, .
. โ -, . .
, AudioSource. AudioSource .
. , .
. .
, , , , .
. , : , , . ( , ).
, . ( )
, , .
โ , . . .
. 2 .
, "", "".
, , . :
, , .
, .
, Play On Awake.
.
, , !
, - โ โฆ !