{"id":1053,"date":"2025-02-27T14:01:46","date_gmt":"2025-02-27T14:01:46","guid":{"rendered":"https:\/\/varnagame.site\/?p=1053"},"modified":"2026-02-25T09:07:56","modified_gmt":"2026-02-25T09:07:56","slug":"unity-%d0%ba%d0%b0%d0%ba-%d0%bf%d1%80%d0%b0%d0%b2%d0%b8%d0%bb%d1%8c%d0%bd%d0%be-%d1%80%d0%b0%d0%b1%d0%be%d1%82%d0%b0%d1%82%d1%8c-%d1%81-%d1%81%d0%be%d0%b1%d1%8b%d1%82%d0%b8%d1%8f%d0%bc%d0%b8","status":"publish","type":"post","link":"https:\/\/varnagame.site\/?p=1053","title":{"rendered":"\u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 event Action"},"content":{"rendered":"\n<p>\u0421\u043e\u0431\u044b\u0442\u0438\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435, \u0433\u0434\u0435 \u043e\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043e, \u0438\u0437\u0432\u043d\u0435 \u0435\u0433\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f. \u041f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u0432\u043d\u0435.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>using System;\nusing UnityEngine;\n\npublic class PlayerInput : MonoBehaviour\n{\n    public static event Action ActionButtonPressed;\n    public static event Action&lt;float&gt; MovementDirectionChanged;\n\n    private void Update()\n    {\n        if (Input.GetKeyDown(KeyCode.F))\n        {\n            ActionButtonPressed?.Invoke(); \/\/ Invoke \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043a\u043b\u0430\u0441\u0441\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438\u0432\u0435\u043d\u0442 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d, \u0438\u0437\u0432\u043d\u0435 \u0435\u0433\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f\n        }\n\n        var direction = Input.GetAxis(&quot;Horizontal&quot;);\n        MovementDirectionChanged?.Invoke(direction);\n    }\n\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u0417\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0438\u0432\u0435\u043d\u0442\u0430&nbsp;<code>ActionButtonPressed<\/code>&nbsp;\u0438&nbsp;<code>MovementDirectionChanged<\/code>. \u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0436\u0430\u0442\u0430 \u043a\u043d\u043e\u043f\u043a\u0430 F, \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043e\u0441\u0438. \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434&nbsp;<code>Invoke<\/code>.<\/p>\n\n\n\n<p>\u0414\u0430\u043b\u0435\u0435 \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043d\u0430 \u044d\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>public class Dummy : MonoBehaviour\n{\n    private void OnEnable()\n    {\n        PlayerInput.ActionButtonPressed += DoStuff; \/\/ += Move \u043d\u0435\u043b\u044c\u0437\u044f, \u0442.\u043a. \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442\n        PlayerInput.MovementDirectionChanged += Move;\n    }\n\n    private void OnDisable()\n    {\n        PlayerInput.ActionButtonPressed -= DoStuff;\n        PlayerInput.MovementDirectionChanged -= Move;\n    }\n\n    private void DoStuff()\n    {\n        \/\/DoStuff\n    }\n\n    private void Move(float direction) \/\/\u0421\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u0441 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u043e\u0439 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430, \u0442.\u0435, \u0435\u0441\u043b\u0438 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 Action&lt;SomeType&gt;, \u0442\u043e \u0443 \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0441 \u0442\u0435\u043c \u0436\u0435 \u0442\u0438\u043f\u043e\u043c, \u0442\u043e \u0431\u0438\u0448\u044c Move(SomeType something)\n    {\n        \/\/\u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 direction\n    }\n}<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u0421\u043e\u0431\u044b\u0442\u0438\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435, \u0433\u0434\u0435 \u043e\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043e, \u0438\u0437\u0432\u043d\u0435 \u0435\u0433\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f. \u041f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,10,20],"tags":[],"_links":{"self":[{"href":"https:\/\/varnagame.site\/index.php?rest_route=\/wp\/v2\/posts\/1053"}],"collection":[{"href":"https:\/\/varnagame.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/varnagame.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/varnagame.site\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/varnagame.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1053"}],"version-history":[{"count":2,"href":"https:\/\/varnagame.site\/index.php?rest_route=\/wp\/v2\/posts\/1053\/revisions"}],"predecessor-version":[{"id":1491,"href":"https:\/\/varnagame.site\/index.php?rest_route=\/wp\/v2\/posts\/1053\/revisions\/1491"}],"wp:attachment":[{"href":"https:\/\/varnagame.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/varnagame.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/varnagame.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}