{"id":182672,"date":"2013-06-09T20:24:03","date_gmt":"2013-06-09T16:24:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=182672"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=182672","title":{"rendered":"<span class=\"post_title\">\u041a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0443\u044e Tower Defense \u0438\u0433\u0440\u0443 \u043d\u0430 Unity3D, \u0447\u0430\u0441\u0442\u044c \u0432\u0442\u043e\u0440\u0430\u044f<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435! \u0412\u0435\u0441\u044c\u043c\u0430 \u043d\u0430\u0434\u043e\u043b\u0433\u043e \u0443 \u043c\u0435\u043d\u044f \u0440\u0430\u0441\u0442\u044f\u043d\u0443\u043b\u0430\u0441\u044c \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 (\u0436\u0438\u0437\u043d\u044c \u0434\u0430\u0432\u0430\u043b\u0430 \u0438\u0437\u0440\u044f\u0434\u043d\u044b\u0445 \u043f\u0438\u043d\u043a\u043e\u0432 \u043f\u043e\u0434 \u0437\u0430\u0434), \u043d\u043e \u0432\u043e\u0442 \u044f \u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0441\u044f \u0438 \u0433\u043e\u0442\u043e\u0432 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0441 \u0432\u0430\u043c\u0438.<\/p>\n<p>  <a href=\"http:\/\/habrahabr.ru\/post\/148410\/\">\u0427\u0430\u0441\u0442\u044c \u043f\u0435\u0440\u0432\u0430\u044f<\/a><\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/dc7\/d6b\/d5a\/dc7d6bd5a92268e9e9e4f1b1ff9af2c8.png\"\/><br \/>  <i>\u041d\u0435\u0443\u0434\u0430\u0447\u043d\u044b\u0439 \u0442\u0435\u0441\u0442 \u0444\u0438\u0437\u0438\u043a\u0438<\/i><\/p>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b:<br \/>   \u2014 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u0434 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438;<br \/>   \u2014 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u00ab\u0431\u0430\u0437\u0430\u00bb \u0438 \u043d\u0430\u0443\u0447\u0438\u043c \u0435\u0451 \u0447\u0438\u043d\u0438\u0442\u044c\u0441\u044f \u0432\u0440\u0435\u043c\u044f \u043e\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438;<br \/>   \u2014 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0443\u0448\u043a\u0430\u043c \u043f\u0430\u0442\u0440\u043e\u043d\u044b \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u0440\u044f\u0434\u043a\u0443;<br \/>   \u2014 \u0438\u0437\u0431\u0430\u0432\u0438\u043c\u0441\u044f \u043e\u0442 \u00ab\u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e\u0439\u00bb \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 gv;<\/p>\n<p>  \u0410 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0432\u0430\u0441 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u0431\u043e\u043d\u0443\u0441 \ud83d\ude42<\/p>\n<p>  \u0412\u0441\u0435\u043c \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u0432\u0448\u0438\u043c\u0441\u044f \u2014 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u0434\u043e\u043b\u0433\u043e\u0436\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u0442!<br \/>  <a name=\"habracut\"><\/a><\/p>\n<h4>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f, \u0431\u0430\u0433\u0444\u0438\u043a\u0441\u044b, \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043d\u0430 \u0441\u0446\u0435\u043d\u0435 \u0438 \u0432\u0441\u0451 \u0442\u0430\u043a\u043e\u0435<\/h4>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u043c\u044b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u043d\u0435\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 <s>\u0433\u043e\u0432\u043d\u043e<\/s>\u043a\u043e\u0434, \u0447\u0442\u043e \u0434\u0430\u0441\u0442 \u043d\u0430\u043c \u0437\u0430\u043f\u0430\u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0438\u0433\u0440\u044b.<\/p>\n<p>  \u041d\u0430\u0447\u043d\u0451\u043c \u0436\u0435 \u043c\u044b \u0441 AI \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u043f\u0443\u0448\u043a\u0438, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043a\u043e\u0441\u043d\u0443\u043b\u0438\u0441\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u043e\u0431\u043e\u0439\u043c\u0430 \u0441 \u043f\u0430\u0442\u0440\u043e\u043d\u0430\u043c\u0438, \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u0440\u044f\u0434\u043a\u0430, \u0434\u043b\u044f\u0449\u0430\u044f\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f:<\/p>\n<p>  <b>PlasmaTurretAI.cs<\/b>  <\/p>\n<pre><code class=\"cs\">using UnityEngine;  public class PlasmaTurretAI : MonoBehaviour { \tpublic GameObject curTarget; \tpublic float towerPrice = 100.0f; \tpublic float attackMaximumDistance = 50.0f; \/\/\u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u044f \u0430\u0442\u0430\u043a\u0438 \tpublic float attackMinimumDistance = 5.0f; \tpublic float attackDamage = 10.0f; \/\/\u0443\u0440\u043e\u043d \tpublic float reloadTimer = 2.5f; \/\/\u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u043c\u0435\u0436\u0434\u0443 \u0432\u044b\u0441\u0442\u0440\u0435\u043b\u0430\u043c\u0438, \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \tpublic float reloadCooldown = 2.5f; \/\/\u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u043c\u0435\u0436\u0434\u0443 \u0432\u044b\u0441\u0442\u0440\u0435\u043b\u0430\u043c\u0438, \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430 \tpublic float rotationSpeed = 1.5f; \/\/\u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u044c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0431\u0430\u0448\u043d\u0438 \tpublic int FiringOrder = 1; \/\/\u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0440\u0435\u043b\u044c\u0431\u044b \u0434\u043b\u044f \u0441\u0442\u0432\u043e\u043b\u043e\u0432 (\u0443 \u043d\u0430\u0441 \u0436\u0435 \u0438\u0445 2) \tpublic int upgradeLevel = 0; \tpublic int ammoAmount = 64; \tpublic int ammoAmountConst = 64; \tpublic float ammoReloadTimer = 5.0f; \tpublic float ammoReloadConst = 5.0f; \tpublic LayerMask turretLayerMask; \/\/\u0432 \u0441\u0430\u043c\u043e\u0439 Unity3D \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 \u0441\u043b\u043e\u0439 \u0434\u043b\u044f \u043c\u043e\u0431\u043e\u0432 \u043f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 \u0442\u0435\u0433\u0430\u043c\u0438 \u0438 \u0432\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u0435\u0433\u043e \u0442\u0443\u0442. \u042f \u043d\u0430\u0437\u0432\u0430\u043b \u0435\u0433\u043e Monster. \u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0430 \u043f\u0440\u0435\u0444\u0430\u0431\u0435 \u043c\u043e\u0431\u0430.  \tpublic Transform turretHead;  \t\/\/\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \tprivate void Start() \t{ \t\tturretHead = transform.Find(&quot;pushka&quot;); \/\/\u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0431\u0430\u0448\u043d\u044e \u0432 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u0447\u0430\u0441\u0442\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \t}  \t\/\/\u0430 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0444\u0440\u0435\u0439\u043c \tprivate void Update() \t{ \t\tif (curTarget != null) \/\/\u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0446\u0435\u043b\u0438 \u043d\u0435 \u043f\u0443\u0441\u0442\u0430\u044f \t\t{ \t\t\tfloat squaredDistance = (turretHead.position - curTarget.transform.position).sqrMagnitude; \/\/\u043c\u0435\u0440\u044f\u0435\u043c \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u044e \u0434\u043e \u043d\u0435\u0435 \t\t\tif (Mathf.Pow(attackMinimumDistance, 2) &lt; squaredDistance && squaredDistance &lt; Mathf.Pow(attackMaximumDistance, 2)) \/\/\u0435\u0441\u043b\u0438 \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043c\u0435\u0440\u0442\u0432\u043e\u0439 \u0437\u043e\u043d\u044b \u0438 \u043c\u0435\u043d\u044c\u0448\u0435 \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u0438 \u043f\u043e\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043f\u0443\u0448\u043a\u0438 \t\t\t{ \t\t\t\tturretHead.rotation = Quaternion.Lerp(turretHead.rotation, Quaternion.LookRotation(curTarget.transform.position - turretHead.position), rotationSpeed * Time.deltaTime); \/\/\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0431\u0430\u0448\u043d\u044e \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u0446\u0435\u043b\u0438 \t\t\t\tif (reloadTimer &gt; 0) reloadTimer -= Time.deltaTime; \/\/\u0435\u0441\u043b\u0438 \u0442\u0430\u0439\u043c\u0435\u0440 \u043f\u0435\u0440\u0435\u0437\u0430\u0440\u044f\u0434\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0443\u043b\u044f - \u043e\u0442\u043d\u0438\u043c\u0430\u0435\u043c \u0435\u0433\u043e \t\t\t\tif (reloadTimer &lt;= 0) \t\t\t\t{ \t\t\t\t\tif (ammoAmount &gt; 0) \/\/\u043f\u043e\u043a\u0430 \u0435\u0441\u0442\u044c \u043f\u043e\u0440\u043e\u0445 \u0432 \u043f\u043e\u0440\u043e\u0445\u043e\u0432\u043d\u0438\u0446\u0430\u0445 \t\t\t\t\t{ \t\t\t\t\t\tMobHP mhp = curTarget.GetComponent&lt;MobHP&gt;(); \t\t\t\t\t\tswitch (FiringOrder) \/\/\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0438\u0437 \u043a\u0430\u043a\u043e\u0433\u043e \u0441\u0442\u0432\u043e\u043b\u0430 \u0441\u0442\u0440\u0435\u043b\u044f\u0442\u044c \t\t\t\t\t\t{ \t\t\t\t\t\t\tcase 1: \t\t\t\t\t\t\t\tif (mhp != null) mhp.ChangeHP(-attackDamage); \/\/\u043d\u0430\u043d\u043e\u0441\u0438\u043c \u0443\u0440\u043e\u043d \u0446\u0435\u043b\u0438 \t\t\t\t\t\t\t\tFiringOrder++; \/\/\u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0441\u0442\u0432\u043e\u043b \t\t\t\t\t\t\t\tammoAmount--; \/\/\u043c\u0438\u043d\u0443\u0441 \u043f\u0430\u0442\u0440\u043e\u043d \t\t\t\t\t\t\t\tbreak; \t\t\t\t\t\t\tcase 2: \t\t\t\t\t\t\t\tif (mhp != null) mhp.ChangeHP(-attackDamage); \t\t\t\t\t\t\t\tFiringOrder = 1; \t\t\t\t\t\t\t\tammoAmount--; \t\t\t\t\t\t\t\tbreak; \t\t\t\t\t\t} \t\t\t\t\t\treloadTimer = reloadCooldown; \/\/\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u043f\u0435\u0440\u0435\u0437\u0430\u0440\u044f\u0434\u043a\u0438 \u0435\u0451 \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 &quot;\u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b&quot; \t\t\t\t\t} \t\t\t\t\telse \t\t\t\t\t{ \t\t\t\t\t\tif (ammoReloadTimer &gt; 0) ammoReloadTimer -= Time.deltaTime; \t\t\t\t\t\tif (ammoReloadTimer &lt;= 0) \t\t\t\t\t\t{ \t\t\t\t\t\t\tammoAmount = ammoAmountConst; \t\t\t\t\t\t\tammoReloadTimer = ammoReloadConst; \t\t\t\t\t\t} \t\t\t\t\t} \t\t\t\t} \t\t\t\tif (squaredDistance &lt; Mathf.Pow(attackMinimumDistance, 2)) curTarget = null;\/\/\u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0441 \u043f\u0440\u0438\u0446\u0435\u043b\u0430 \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0446\u0435\u043b\u044c, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0432\u043d\u0435 \u0440\u0430\u0434\u0438\u0443\u0441\u0430 \u0430\u0442\u0430\u043a\u0438 \t\t\t} \t\t} \t\telse \t\t{ \t\t\tcurTarget = SortTargets(); \/\/\u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0446\u0435\u043b\u0438 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u043e\u0432\u0443\u044e \t\t} \t}  \t\/\/\u041c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u0438\u0441\u043a\u0430 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0439 \u0446\u0435\u043b\u0438 \tprivate GameObject SortTargets() \t{ \t\tfloat closestMobSquaredDistance = 0; \/\/\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0430 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0433\u043e \u043c\u043e\u0431\u0430 \t\tGameObject nearestmob = null; \/\/\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0433\u043e \u043c\u043e\u0431\u0430 \t\tCollider[] mobColliders = Physics.OverlapSphere(transform.position, attackMaximumDistance, turretLayerMask.value); \/\/\u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043a\u043e\u043b\u043b\u0430\u0439\u0434\u0435\u0440\u044b \u0432\u0441\u0435\u0445 \u043c\u043e\u0431\u043e\u0432 \u0432 \u0440\u0430\u0434\u0438\u0443\u0441\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0430\u0442\u0430\u043a\u0438 \u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438  \t\tforeach (var mobCollider in mobColliders) \/\/\u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043e\u043b\u043b\u0430\u0439\u0434\u0435\u0440\u0430 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \t\t{ \t\t\tfloat distance = (mobCollider.transform.position - turretHead.position).sqrMagnitude; \t\t\t\/\/\u0435\u0441\u043b\u0438 \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u044f \u0434\u043e \u043c\u043e\u0431\u0430 \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c closestMobDistance \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u0430 \u043d\u0443\u043b\u044e \t\t\tif (distance &lt; closestMobSquaredDistance && (distance &gt; Mathf.Pow(attackMinimumDistance, 2)) || closestMobSquaredDistance == 0) \t\t\t{ \t\t\t\tclosestMobSquaredDistance = distance; \/\/\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0435\u0451 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \t\t\t\tnearestmob = mobCollider.gameObject;\/\/\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043c\u043e\u0431\u0430 \u043a\u0430\u043a \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0433\u043e \t\t\t} \t\t} \t\treturn nearestmob; \/\/ \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0435\u0433\u043e \t}  \tprivate void OnGUI() \t{ \t\tVector3 screenPosition = Camera.main.WorldToScreenPoint(gameObject.transform.position); \/\/\u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0438\u0440\u0430 \t\tVector3 cameraRelative = Camera.main.transform.InverseTransformPoint(transform.position); \/\/\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043e\u0442 \u043a\u0430\u043c\u0435\u0440\u044b \t\tif (cameraRelative.z &gt; 0) \/\/\u0435\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u043f\u0435\u0440\u0435\u0434\u0438 \u043a\u0430\u043c\u0435\u0440\u044b \t\t{ \t\t\tstring ammoString; \t\t\tif (ammoAmount &gt; 0) \t\t\t{ \t\t\t\tammoString = ammoAmount + &quot;\/&quot; + ammoAmountConst; \t\t\t} \t\t\telse \t\t\t{ \t\t\t\tammoString = &quot;Reloading: &quot; + (int)ammoReloadTimer + &quot; s left&quot;; \t\t\t} \t\t\tGUI.Label(new Rect(screenPosition.x, Screen.height - screenPosition.y, 250f, 20f), ammoString); \t\t} \t} } <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0442\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u0447\u0451\u0442 \u0447\u0435\u0440\u0435\u0437 \u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0435\u0433\u043e \u0441 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u0443\u0448\u043a\u0438. \u042d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0442.\u043a. \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f Sqrt. \u0421\u043f\u0430\u0441\u0438\u0431\u043e <a href=\"http:\/\/habrahabr.ru\/users\/leopotam\/\" class=\"user_link\">Leopotam<\/a> \u0437\u0430 \u0441\u043e\u0432\u0435\u0442 \ud83d\ude42<\/p>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043c \u0441\u0446\u0435\u043d\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/a21\/e74\/67a\/a21e7467a0402ab9561b84979ca3d3c9.jpg\"\/><\/p>\n<p>  \u041a\u0440\u0430\u0441\u043d\u044b\u043c\u0438 \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u044f \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043b \u043c\u0435\u0441\u0442\u0430 \u0441\u043f\u0430\u0443\u043d\u043f\u043e\u0439\u043d\u0442\u043e\u0432, \u043f\u043e \u0446\u0435\u043d\u0442\u0440\u0443 \u0443 \u043c\u0435\u043d\u044f \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u00ab\u0431\u0430\u0437\u0430\u00bb \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043c\u0430\u043a\u0441\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u0447\u0430\u0439\u043d\u0438\u043a\u0430 \ud83d\ude42<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/a83\/2a3\/868\/a832a3868018869a7386a6d31dad2173.jpg\"\/><\/p>\n<p>  \u041d\u0430 \u0431\u0430\u0437\u0443 \u044f \u043f\u043e\u0432\u0435\u0441\u0438\u043b \u0442\u0435\u0433 Base, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0435\u0451 \u043b\u0435\u0433\u043a\u043e \u043d\u0430\u0439\u0442\u0438.<br \/>  \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0431\u044b \u0448\u043b\u0438 \u043f\u0440\u044f\u043c\u043e \u043a \u0431\u0430\u0437\u0435, \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u044f \u043f\u0443\u0448\u043a\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0443\u0447\u0438\u0442\u044c \u0431\u0430\u0437\u0443 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u0443\u0440\u043e\u043d \u0438 \u0447\u0438\u043d\u0438\u0442\u044c\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b.<br \/>  \u0427\u0442\u043e \u0436, \u043d\u0430\u0447\u043d\u0451\u043c:<\/p>\n<p>  <b>BaseHP.cs<\/b>  <\/p>\n<pre><code class=\"cs\">using UnityEngine;   public class BaseHP : MonoBehaviour {    public float maxHP = 1000;    public float curHP = 1000;    public float regenerationDelayConstant = 2.5f; \/\/\u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 \u043c\u0435\u0436\u0434\u0443 \u0440\u0435\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0435\u0439 \u0445\u043f \u0431\u0430\u0437\u044b    public float regenarationDelayVariable = 2.5f; \/\/\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0442\u043e\u0439 \u0436\u0435 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438    public float regenerationAmount = 10.0f; \/\/\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u0445\u043f \u043f\u0440\u0438 \u0440\u0435\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0437\u0430 \u0440\u0430\u0437      private GlobalVars gv;      private void Awake()    {       gv = GameObject.Find(&quot;GlobalVars&quot;).GetComponent&lt;GlobalVars&gt;();       if (maxHP &lt; 1) maxHP = 1;    }      public void ChangeHP(float adjust)    {       if ((curHP + adjust) &gt; maxHP) curHP = maxHP;       else curHP += adjust;       if (curHP &gt; maxHP) curHP = maxHP; \/\/just in case    }      private void Update()    {       if (curHP &lt;= 0)       {          Destroy(gameObject);       }       else       {          if (regenarationDelayVariable &gt; 0) regenarationDelayVariable -= Time.deltaTime; \/\/\u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 \u0431\u043e\u043b\u0435\u0435 \u043d\u0443\u043b\u044f - \u043e\u0442\u043d\u0438\u043c\u0430\u0435\u043c \u043e\u0442 \u043d\u0435\u0451 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443          if (regenarationDelayVariable &lt;= 0) \/\/\u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0441\u0442\u0430\u043b\u0430 \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u0430 \u043d\u0443\u043b\u044e          {             ChangeHP(regenerationAmount); \/\/\u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0440\u0430\u043d\u0435\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0425\u041f             regenarationDelayVariable = regenerationDelayConstant; \/\/\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043d\u0430\u0448\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0432 \u0435\u0451 \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435          }       }    } } <\/code><\/pre>\n<p>  \u0412\u0435\u0448\u0430\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u043d\u0430 \u043d\u0430\u0448 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0431\u0430\u0437\u043e\u0439. \u041e\u043d\u0430 \u0433\u043e\u0442\u043e\u0432\u0430, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e \u043c\u043e\u0431\u043e\u0432!<\/p>\n<p>  \u0412 \u0441\u043a\u0440\u0438\u043f\u0442\u0435 AI \u043c\u043e\u0431\u043e\u0432 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044e \u043f\u043e\u0434\u043b\u0435\u0436\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434 Update, \u043f\u043e\u0442\u043e\u043c\u0443 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0443:<\/p>\n<p>  <b>MobAI.cs<\/b>  <\/p>\n<pre><code class=\"cs\">private void Update()    {       if (Target != null)       {          mob.rotation = Quaternion.Lerp(mob.rotation, Quaternion.LookRotation(new Vector3(Target.transform.position.x, 0.0f, Target.transform.position.z) - new Vector3(mob.position.x, 0.0f, mob.position.z)), mobRotationSpeed);          mob.position += mob.forward * MobCurrentSpeed * Time.deltaTime;          float squaredDistance = (Target.transform.position - mob.position).sqrMagnitude; \/\/\u043c\u0435\u0440\u044f\u0435\u043c \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u044e \u0434\u043e \u0446\u0435\u043b\u0438          Vector3 structDirection = (Target.transform.position - mob.position).normalized;          float attackDirection = Vector3.Dot(structDirection, mob.forward);          if (squaredDistance &lt; attackDistance * attackDistance && attackDirection &gt; 0)          {             if (attackTimer &gt; 0) attackTimer -= Time.deltaTime;             if (attackTimer &lt;= 0)             {                BaseHP bhp = Target.GetComponent&lt;BaseHP&gt;(); \/\/\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443 HP \u0446\u0435\u043b\u0438                if (bhp != null) bhp.ChangeHP(-damage); \/\/ \u043e\u0442\u043d\u0438\u043c\u0430\u0435\u043c \u043e\u0442 \u0435\u0451 HP \u043d\u0430\u0448 \u0443\u0440\u043e\u043d                attackTimer = coolDown;             }          }       }       else       {          GameObject baseGO = GameObject.FindGameObjectWithTag(&quot;Base&quot;); \/\/\u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043d\u0430\u0448 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0431\u0430\u0437\u043e\u0439, \u043e\u043d \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d          if (baseGO != null) Target = baseGO; \/\/\u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 - \u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0451 \u0446\u0435\u043b\u044c\u044e \u0434\u043b\u044f \u043c\u043e\u0431\u0430.       }    } <\/code><\/pre>\n<p>  \u0412\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e, \u043c\u043e\u0431\u044b \u043f\u043e\u043b\u0437\u0443\u0442 \u043a\u0443\u0441\u0430\u0442\u044c \u0431\u0430\u0437\u0443, \u043f\u0443\u0448\u043a\u0438 \u043c\u0435\u0442\u043e\u0434\u0438\u0447\u043d\u043e \u043e\u0442\u0441\u0442\u0440\u0435\u043b\u0438\u0432\u0430\u044e\u0442 \u043d\u0430\u0445\u0430\u043b\u043e\u0432. \u041d\u043e \u043a\u0430\u043c\u0435\u0440\u0430-\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u0430\u044f! \u041d\u0435\u043f\u043e\u0440\u044f\u0434\u043e\u043a, \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c:<\/p>\n<p>  <b>CameraControl.cs<\/b>  <\/p>\n<pre><code class=\"cs\">using UnityEngine;   public class CameraControl : MonoBehaviour {    public float CameraSpeed = 100.0f; \/\/\u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f \u043a\u0430\u043c\u0435\u0440\u044b    public float CameraSpeedBoostMultiplier = 2.0f; \/\/\u041c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u044c \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f \u043a\u0430\u043c\u0435\u0440\u044b \u043f\u0440\u0438 \u0437\u0430\u0436\u0430\u0442\u043e\u043c Shift      \/\/\u0417\u0430\u0434\u0430\u0451\u043c \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u043a\u0430\u043c\u0435\u0440\u044b, \u0437\u0434\u0435\u0441\u044c \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043c\u043e\u044f - \u043c\u0435\u043d\u044f\u0439\u0442\u0435 \u043f\u043e\u0434 \u0441\u0435\u0431\u044f    public float DefaultCameraPosX = 888.0f;    public float DefaultCameraPosY = 50.0f;    public float DefaultCameraPosZ = 1414.0f;      private void Awake()    {       \/\/\u0417\u0430\u0434\u0430\u0451\u043c \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u043a\u0430\u043c\u0435\u0440\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0440\u0430\u043d\u0435\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b       transform.position = new Vector3(DefaultCameraPosX, DefaultCameraPosY, DefaultCameraPosZ);    }      private void Update()    {       float smoothCamSpeed = CameraSpeed * Time.smoothDeltaTime; \/\/\u043c\u043d\u043e\u0436\u0438\u043c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043a\u0430\u043c\u0435\u0440\u044b \u043d\u0430 \u0441\u0433\u043b\u0430\u0436\u0435\u043d\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e Time.deltaTime         \/\/\u041f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u0438\u0437 \u043a\u043d\u043e\u043f\u043a\u0438 \u0438\u0437 WASD \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443, \u043d\u0430\u0436\u0430\u043d\u0438\u044f \u0441\u0440\u0430\u0437\u0443 \u0434\u0432\u0443\u0445 \u043a\u043d\u043e\u043f\u043e\u043a \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f (WA \u0431\u0443\u0434\u0435\u0442 \u0434\u0432\u0438\u0433\u0430\u0442\u044c \u043a\u0430\u043c\u0435\u0440\u0443 \u0432\u0432\u0435\u0440\u0445 \u0438 \u0432\u043b\u0435\u0432\u043e), \u0437\u0430\u0436\u0430\u0442\u0438\u0435 Shift \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435.       if (Input.GetKey(KeyCode.W)) transform.position += Input.GetKey(KeyCode.LeftShift) ? new Vector3(0.0f, 0.0f, smoothCamSpeed * CameraSpeedBoostMultiplier) : new Vector3(0.0f, 0.0f, smoothCamSpeed); \/\/\u0432\u0432\u0435\u0440\u0445       if (Input.GetKey(KeyCode.A)) transform.position += Input.GetKey(KeyCode.LeftShift) ? new Vector3(-smoothCamSpeed * CameraSpeedBoostMultiplier, 0.0f, 0.0f) : new Vector3(-smoothCamSpeed, 0.0f, 0.0f); \/\/\u043d\u0430\u043b\u0435\u0432\u043e       if (Input.GetKey(KeyCode.S)) transform.position += Input.GetKey(KeyCode.LeftShift) ? new Vector3(0.0f, 0.0f, -smoothCamSpeed * CameraSpeedBoostMultiplier) : new Vector3(0.0f, 0.0f, -smoothCamSpeed); \/\/\u0432\u043d\u0438\u0437       if (Input.GetKey(KeyCode.D)) transform.position += Input.GetKey(KeyCode.LeftShift) ? new Vector3(smoothCamSpeed * CameraSpeedBoostMultiplier, 0.0f, 0.0f) : new Vector3(smoothCamSpeed, 0.0f, 0.0f); \/\/\u043d\u0430\u043f\u0440\u0430\u0432\u043e    } } <\/code><\/pre>\n<p>  \u0421\u043a\u0440\u0438\u043f\u0442, \u0441\u0430\u043c\u043e \u0441\u043e\u0431\u043e\u0439, \u0432\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043a\u0430\u043c\u0435\u0440\u0443. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0451 \u0434\u0432\u0438\u0433\u0430\u0435\u0442\u0441\u044f, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0432\u043e\u043a\u0440\u0443\u0433 \u043d\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u043a \u0431\u0430\u0437\u0435 \u043c\u043e\u0431\u043e\u0432, \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0443\u0448\u043a\u0438 \u0435\u0449\u0451 \u043d\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0435.<\/p>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0431\u0430\u0433\u0444\u0438\u043a\u0441 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u044c \u043f\u0443\u0448\u043a\u0438 \u00ab\u0432 \u043a\u0440\u0435\u0434\u0438\u0442\u00bb. \u0414\u0430, \u043d\u0443\u0436\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0434\u0435\u043d\u0435\u0433 \u0438\u0433\u0440\u043e\u043a\u0430 \u0438 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0443\u0448\u043a\u0438. \u041f\u0440\u0430\u0432\u0438\u043c \u044d\u0442\u043e \u0434\u0435\u043b\u043e:<br \/>  <b>Graphic.cs<\/b>  <\/p>\n<pre><code class=\"cs\">private void OnGUI()    {       GUI.Box(buyMenu, &quot;Buying menu&quot;); \/\/\u0414\u0435\u043b\u0430\u0435\u043c \u0433\u0443\u0435\u0432\u0441\u043a\u0438\u0439 \u0431\u043e\u043a\u0441 \u043d\u0430 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0435 buyMenu \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u043c, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c \u043c\u0435\u0436\u0434\u0443 &quot;&quot;       if (GUI.Button(firstTower, &quot;Plasma Tower\\n&quot; + (int)TowerPrices.Plasma + &quot;$&quot;)) \/\/\u0435\u0441\u043b\u0438 \u0438\u0434\u0451\u0442 \u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u043d\u0430 \u043f\u0435\u0440\u0432\u0443\u044e \u043a\u043d\u043e\u043f\u043a\u0443       {          if (gv.PlayerMoney &gt;= (int)TowerPrices.Plasma) \/\/\u0435\u0441\u043b\u0438 \u0443 \u0438\u0433\u0440\u043e\u043a\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0435\u043d\u0435\u0433             gv.mau5tate = GlobalVars.ClickState.Placing; \/\/\u043c\u0435\u043d\u044f\u0435\u043c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u044b\u0448\u0438 \u043d\u0430 &quot;\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0443\u0448\u043a\u0438&quot;       }       if (GUI.Button(secondTower, &quot;Pulse Tower\\n&quot; + (int)TowerPrices.Pulse + &quot;$&quot;)) \/\/\u0441 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e       {          \/\/same action here       }       if (GUI.Button(thirdTower, &quot;Beam Tower\\n&quot; + (int)TowerPrices.Beam + &quot;$&quot;))       {          \/\/same action here       }       if (GUI.Button(fourthTower, &quot;Tesla Tower\\n&quot; + (int)TowerPrices.Tesla + &quot;$&quot;))       {          \/\/same action here       }       if (GUI.Button(fifthTower, &quot;Artillery Tower\\n&quot; + (int)TowerPrices.Artillery + &quot;$&quot;))       {          \/\/same action here       }         GUI.Box(playerStats, &quot;Player Stats&quot;);       GUI.Label(playerStatsPlayerMoney, &quot;Money: &quot; + gv.PlayerMoney + &quot;$&quot;);         GUI.Box(towerMenu, &quot;Tower menu&quot;);       if (GUI.Button(towerMenuSellTower, &quot;Sell&quot;))       {          \/\/action here       }       if (GUI.Button(towerMenuUpgradeTower, &quot;Upgrade&quot;))       {          \/\/same action here       }    }      \/\/\u0446\u0435\u043d\u044b \u043d\u0430 \u043f\u0443\u0448\u043a\u0438    private enum TowerPrices    {       Plasma = 100,       Pulse = 150,       Beam = 250,       Tesla = 300,       Artillery = 350    } <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435, \u0443\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u043a\u043e\u0434\u0430, \u044f \u0438\u0437\u0431\u0430\u0432\u0438\u043b\u0441\u044f \u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 GlobalVars, \u0441\u0434\u0435\u043b\u0430\u0432 \u0435\u0433\u043e \u0438 \u0432\u0441\u0435 \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 static.<\/p>\n<p>  <b>GlobalVars.cs<\/b>  <\/p>\n<pre><code class=\"cs\">using System.Collections.Generic; using UnityEngine;  public static class GlobalVars { \tpublic static List&lt;GameObject&gt; MobList = new List&lt;GameObject&gt;(); \/\/\u043c\u0430\u0441\u0441\u0438\u0432 \u043c\u043e\u0431\u043e\u0432 \u0432 \u0438\u0433\u0440\u0435 \tpublic static int MobCount = 0; \/\/\u0441\u0447\u0435\u0442\u0447\u0438\u043a \u043c\u043e\u0431\u043e\u0432 \u0432 \u0438\u0433\u0440\u0435  \tpublic static List&lt;GameObject&gt; TurretList = new List&lt;GameObject&gt;(); \/\/\u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0443\u0448\u0435\u043a \u0432 \u0438\u0433\u0440\u0435 \tpublic static int TurretCount = 0; \/\/\u0441\u0447\u0435\u0442\u0447\u0438\u043a \u043f\u0443\u0448\u0435\u043a \u0432 \u0438\u0433\u0440\u0435  \tpublic static float PlayerMoney = 200.0f; \/\/\u043f\u0440\u0438 \u0441\u0442\u0430\u0440\u0442\u0435 \u0438\u0433\u0440\u044b, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442\u0443 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u043e \u0434\u0435\u043d\u044c\u0433\u0438 \u0438\u0433\u0440\u043e\u043a\u0430 - \u0438\u0445 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f 200$, \u0438\u043d\u0430\u0447\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u043f\u0430\u043c\u044f\u0442\u0438  \tpublic static ClickState mau5tate = ClickState.Default; \/\/\u0434\u0435\u0444\u043e\u043b\u0442\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u0443\u0440\u0441\u043e\u0440\u0430  \tpublic enum ClickState \/\/\u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u043a\u0443\u0440\u0441\u043e\u0440\u0430 \t{ \t\tDefault, \/\/\u043e\u0431\u044b\u0447\u043d\u043e\u0435 \t\tPlacing, \/\/\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u0443\u0448\u043a\u0443 \t\tSelling, \/\/\u043f\u0440\u043e\u0434\u0430\u0451\u043c \u043f\u0443\u0448\u043a\u0443 \t\tUpgrading \/\/\u0443\u043b\u0443\u0447\u0448\u0430\u0435\u043c \u043f\u0443\u0448\u043a\u0443 \t} } <\/code><\/pre>\n<p>  \u0412\u043e \u0432\u0441\u0435\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445, \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f GlobalVars, \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 gv, \u0438\u0445 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432 Awake(). \u0417\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0432\u0441\u0435 gv \u043d\u0430 GlobalVars. \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 GlobalVars \u043d\u0430 null. \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 GlobalVars \u0438\u0437 \u043e\u0434\u043d\u043e\u0438\u043c\u0451\u043d\u043d\u043e\u0433\u043e \u0413\u041e (\u043c\u043e\u0436\u043d\u043e \u0441\u0430\u043c \u0413\u041e \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c \u0432\u043e \u0447\u0442\u043e-\u0442\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, cfg).<br \/>  \u042f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043f\u043e\u043b\u043d\u044b\u0435 \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0432\u0430\u043c \u0431\u044b\u043b\u043e, \u0441 \u0447\u0435\u043c \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u044d\u0442\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u041e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e, \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u044b \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438! \ud83d\ude42<br \/>  <b>Graphic.cs<\/b>  <\/p>\n<pre><code class=\"cs\">using UnityEngine;  public class Graphic : MonoBehaviour { \tpublic Rect buyMenu; \/\/\u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u043c\u0435\u043d\u044e \u043f\u043e\u043a\u0443\u043f\u043a\u0438 \tpublic Rect firstTower; \/\/\u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u043a\u043d\u043e\u043f\u043a\u0438 \u043f\u043e\u043a\u0443\u043f\u043a\u0438 \u043f\u0435\u0440\u0432\u043e\u0439 \u0431\u0430\u0448\u043d\u0438 \tpublic Rect secondTower; \/\/\u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u043a\u043d\u043e\u043f\u043a\u0438 \u043f\u043e\u043a\u0443\u043f\u043a\u0438 \u0432\u0442\u043e\u0440\u043e\u0439 \u0431\u0430\u0448\u043d\u0438 \tpublic Rect thirdTower; \/\/\u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u043a\u043d\u043e\u043f\u043a\u0438 \u043f\u043e\u043a\u0443\u043f\u043a\u0438 \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u0431\u0430\u0448\u043d\u0438 \tpublic Rect fourthTower; \/\/\u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u043a\u043d\u043e\u043f\u043a\u0438 \u043f\u043e\u043a\u0443\u043f\u043a\u0438 \u0447\u0435\u0442\u0432\u0451\u0440\u0442\u043e\u0439 \u0431\u0430\u0448\u043d\u0438 \tpublic Rect fifthTower; \/\/\u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u043a\u043d\u043e\u043f\u043a\u0438 \u043f\u043e\u043a\u0443\u043f\u043a\u0438 \u043f\u044f\u0442\u043e\u0439 \u0431\u0430\u0448\u043d\u0438  \tpublic Rect towerMenu; \/\/\u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u044e \u0431\u0430\u0448\u043d\u0438 (\u043f\u0440\u043e\u0434\u0430\u0442\u044c\/\u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c) \tpublic Rect towerMenuSellTower; \/\/\u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u043a\u043d\u043e\u043f\u043a\u0438 \u043f\u0440\u043e\u0434\u0430\u0436\u0438 \u0431\u0430\u0448\u043d\u0438 \tpublic Rect towerMenuUpgradeTower; \/\/\u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u043a\u043d\u043e\u043f\u043a\u0438 \u0430\u043f\u0433\u0440\u0435\u0439\u0434\u0430 \u0431\u0430\u0448\u043d\u0438  \tpublic Rect playerStats; \/\/\u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0438\u0433\u0440\u043e\u043a\u0430 \tpublic Rect playerStatsPlayerMoney; \/\/\u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u0437\u043e\u043d\u044b \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0434\u0435\u043d\u0435\u0433 \u0438\u0433\u0440\u043e\u043a\u0430  \tpublic GameObject plasmaTower; \/\/\u043f\u0440\u0435\u0444\u0430\u0431 \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u0443\u0448\u043a\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u0432 \u0438\u043d\u0441\u043f\u0435\u043a\u0442\u043e\u0440\u0435 \tpublic GameObject plasmaTowerGhost; \/\/\u043f\u0440\u0438\u0437\u0440\u0430\u043a \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u0443\u0448\u043a\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u0432 \u0438\u043d\u0441\u043f\u0435\u043a\u0442\u043e\u0440\u0435 \tprivate RaycastHit hit; \/\/\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u0440\u0435\u0439\u043a\u0430\u0441\u0442\u0430 \tpublic LayerMask buildRaycastLayers = 1; \tpublic LayerMask upgradeRaycastLayer; \/\/\u0441\u043b\u043e\u0439 \u0434\u043b\u044f \u0430\u043f\u0433\u0440\u0435\u0439\u0434\u0430 \tpublic LayerMask sellRaycastLayer; \/\/\u0441\u043b\u043e\u0439 \u0434\u043b\u044f \u043f\u0440\u043e\u0434\u0430\u0436\u0438  \tprivate GameObject ghost; \/\/\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u043f\u0440\u0438\u0437\u0440\u0430\u043a\u0430 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u043f\u0443\u0448\u043a\u0438  \tprivate void Awake() \t{ \t\tbuyMenu = new Rect(Screen.width - 185.0f, 10.0f, 175.0f, Screen.height - 100.0f); \/\/\u0437\u0430\u0434\u0430\u0451\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432, \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0437\u0438\u0446\u0438\u044f X, Y, \u0428\u0438\u0440\u0438\u043d\u0430, \u0412\u044b\u0441\u043e\u0442\u0430. X \u0438 Y \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u043b\u0435\u0432\u044b\u0439 \u0432\u0435\u0440\u0445\u043d\u0438\u0439 \u0443\u0433\u043e\u043b \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \t\tfirstTower = new Rect(buyMenu.x + 12.5f, buyMenu.y + 30.0f, 150.0f, 50.0f); \t\tsecondTower = new Rect(firstTower.x, buyMenu.y + 90.0f, 150.0f, 50.0f); \t\tthirdTower = new Rect(firstTower.x, buyMenu.y + 150.0f, 150.0f, 50.0f); \t\tfourthTower = new Rect(firstTower.x, buyMenu.y + 210.0f, 150.0f, 50.0f); \t\tfifthTower = new Rect(firstTower.x, buyMenu.y + 270.0f, 150.0f, 50.0f);  \t\tplayerStats = new Rect(10.0f, 10.0f, 150.0f, 100.0f); \t\tplayerStatsPlayerMoney = new Rect(playerStats.x + 12.5f, playerStats.y + 30.0f, 125.0f, 25.0f);  \t\ttowerMenu = new Rect(10.0f, Screen.height - 60.0f, 400.0f, 50.0f); \t\ttowerMenuSellTower = new Rect(towerMenu.x + 12.5f, towerMenu.y + 20.0f, 75.0f, 25.0f); \t\ttowerMenuUpgradeTower = new Rect(towerMenuSellTower.x + 5.0f + towerMenuSellTower.width, towerMenuSellTower.y, 75.0f, 25.0f); \t}  \tprivate void Update() \t{ \t\tswitch (GlobalVars.mau5tate) \/\/\u0441\u0432\u0438\u0442\u0447\u0438\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u0443\u0440\u0441\u043e\u0440\u0430 \u043c\u044b\u0448\u0438 \t\t{ \t\t\tcase GlobalVars.ClickState.Placing: \/\/\u0435\u0441\u043b\u0438 \u043e\u043d \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0431\u0430\u0448\u0435\u043d \t\t\t\t{ \t\t\t\t\tif (ghost == null) ghost = Instantiate(plasmaTowerGhost) as GameObject; \/\/\u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043f\u0440\u0438\u0437\u0440\u0430\u043a\u0430 \u043f\u0443\u0441\u0442\u0430\u044f - \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0432 \u043d\u0435\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0440\u0438\u0437\u0440\u0430\u043a\u0430 \u0431\u0430\u0448\u043d\u0438 \t\t\t\t\telse \t\t\t\t\t{ \t\t\t\t\t\tRay scrRay = Camera.main.ScreenPointToRay(Input.mousePosition); \/\/\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043b\u0443\u0447, \u0431\u044c\u044e\u0449\u0438\u0439 \u043e\u0442 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442 \u043c\u044b\u0448\u0438 \u043f\u043e \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u043c \u0432 \u0438\u0433\u0440\u0435 \t\t\t\t\t\tif (Physics.Raycast(scrRay, out hit, Mathf.Infinity, buildRaycastLayers)) \/\/ \u0431\u044c\u0451\u043c \u044d\u0442\u0438\u043c \u043b\u0443\u0447\u0435\u043c \u0432 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c \u0432\u044b\u0448\u0435 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 (\u0442.\u0435. \u0432 \u0437\u0435\u043c\u043b\u044e) \t\t\t\t\t\t{ \t\t\t\t\t\t\tQuaternion normana = Quaternion.FromToRotation(Vector3.up, hit.normal); \/\/\u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u043e\u0440\u043c\u0430\u043b\u044c \u043e\u0442 \u0441\u0442\u043e\u043b\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \t\t\t\t\t\t\tghost.transform.position = hit.point; \/\/\u0437\u0430\u0434\u0430\u0451\u043c \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043fz\u0440\u0438\u0437\u0440\u0430\u043a\u0430 \u0440\u0430\u0432\u043d\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0442\u043e\u0447\u043a\u0438 \u0443\u0434\u0430\u0440\u0430 \u043b\u0443\u0447\u0430 \u043f\u043e \u0437\u0435\u043c\u043b\u0435 \t\t\t\t\t\t\tghost.transform.rotation = normana; \/\/\u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0438 \u0441 \u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435\u043c, \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u043e\u0442 \u0442\u043e\u0447\u043a\u0438, \u0430 \u043e\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u0438 \t\t\t\t\t\t\tif (Input.GetMouseButtonDown(0)) \/\/\u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u041b\u041a\u041c \t\t\t\t\t\t\t{ \t\t\t\t\t\t\t\tGameObject tower = Instantiate(plasmaTower, ghost.transform.position, ghost.transform.rotation) as GameObject; \/\/\u0421\u043f\u0430\u0443\u043d\u0438\u043c \u0431\u0430\u0448\u0435\u043d\u043a\u0443 \u043d\u0430 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043f\u0440\u0438\u0437\u0440\u0430\u043a\u0430 \t\t\t\t\t\t\t\tif (tower != null) \t\t\t\t\t\t\t\t{ \t\t\t\t\t\t\t\t\tGlobalVars.PlayerMoney -= tower.GetComponent&lt;PlasmaTurretAI&gt;().towerPrice; \/\/\u043e\u0442\u043d\u0438\u043c\u0430\u0435\u043c \u043b\u0430\u0432\u0435 \u0437\u0430 \u0431\u0430\u0448\u043d\u044e \t\t\t\t\t\t\t\t\tGlobalVars.TurretCount++; \t\t\t\t\t\t\t\t}  \t\t\t\t\t\t\t\tDestroy(ghost); \/\/\u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0435\u043c \u043f\u0440\u0438\u0437\u0440\u0430\u043a \u0431\u0430\u0448\u043d\u0438 \t\t\t\t\t\t\t\tGlobalVars.mau5tate = GlobalVars.ClickState.Default; \/\/\u043c\u0435\u043d\u044f\u0435\u043c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u044b\u0448\u0438 \u043d\u0430 \u043e\u0431\u044b\u0447\u043d\u043e\u0435 \t\t\t\t\t\t\t} \t\t\t\t\t\t} \t\t\t\t\t} \t\t\t\t\tbreak; \t\t\t\t} \t\t\tcase GlobalVars.ClickState.Upgrading: \t\t\t\t{ \t\t\t\t\t\/\/Ray scrRay = Camera.main.ScreenPointToRay(Input.mousePosition); \/\/\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043b\u0443\u0447, \u0431\u044c\u044e\u0449\u0438\u0439 \u043e\u0442 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442 \u043c\u044b\u0448\u0438 \u043f\u043e \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u043c \u0432 \u0438\u0433\u0440\u0435 \t\t\t\t\t\/\/if (Physics.Raycast(scrRay, out hit, Mathf.Infinity)) \/\/ \u0431\u044c\u0451\u043c \u044d\u0442\u0438\u043c \u043b\u0443\u0447\u0435\u043c \u0432 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c \u0432\u044b\u0448\u0435 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 (\u0442.\u0435. \u0432 \u0437\u0435\u043c\u043b\u044e) \t\t\t\t\t\/\/{ \t\t\t\t\t\/\/\tCollider[] colls = Physics.OverlapSphere(hit.point, 10.0f); \t\t\t\t\t\/\/\tfloat closestMobSquaredDistance = 0; \t\t\t\t\t\/\/\tGameObject nearestObject = null; \t\t\t\t\t\/\/\tif (Input.GetMouseButtonDown(0) && GlobalVars.PlayerMoney &gt;= 1000.0f) \/\/\u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u041b\u041a\u041c \u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0431\u043e\u043b\u0435\u0435 1000$ \u0434\u0435\u043d\u0435\u0433 \t\t\t\t\t\/\/\t{ \t\t\t\t\t\/\/\t\tforeach (Collider coll in colls) \t\t\t\t\t\/\/\t\t{ \t\t\t\t\t\/\/\t\t\tfloat distance = (coll.transform.position - hit.point).sqrMagnitude; \t\t\t\t\t\/\/\t\t\tif (distance &lt; 100f || closestMobSquaredDistance == 0.0f) \t\t\t\t\t\/\/\t\t\t{ \t\t\t\t\t\/\/\t\t\t\tclosestMobSquaredDistance = distance; \t\t\t\t\t\/\/\t\t\t\tnearestObject = coll.gameObject; \t\t\t\t\t\/\/\t\t\t} \t\t\t\t\t\/\/\t\t} \t\t\t\t\t\/\/\t\tif (nearestObject != null) \t\t\t\t\t\/\/\t\t{ \t\t\t\t\t\/\/\t\t\tswitch (nearestObject.tag) \t\t\t\t\t\/\/\t\t\t{ \t\t\t\t\t\/\/\t\t\t\tcase &quot;Turret&quot;: \t\t\t\t\t\/\/\t\t\t\t\t{ \t\t\t\t\t\/\/\t\t\t\t\t\tGlobalVars.mau5tate = GlobalVars.ClickState.Default; \t\t\t\t\t\/\/\t\t\t\t\t\tbreak; \t\t\t\t\t\/\/\t\t\t\t\t} \t\t\t\t\t\/\/\t\t\t\tcase &quot;Base&quot;: \t\t\t\t\t\/\/\t\t\t\t\t{ \t\t\t\t\t\/\/\t\t\t\t\t\tnearestObject.GetComponent&lt;BaseHP&gt;().Upgrade(); \t\t\t\t\t\/\/\t\t\t\t\t\tGlobalVars.mau5tate = GlobalVars.ClickState.Default; \t\t\t\t\t\/\/\t\t\t\t\t\tbreak; \t\t\t\t\t\/\/\t\t\t\t\t} \t\t\t\t\t\/\/\t\t\t\tdefault: \t\t\t\t\t\/\/\t\t\t\t\tGlobalVars.mau5tate = GlobalVars.ClickState.Default; \t\t\t\t\t\/\/\t\t\t\t\tbreak; \t\t\t\t\t\/\/\t\t\t} \t\t\t\t\t\/\/\t\t} \t\t\t\t\t\/\/\t} \t\t\t\t\t\/\/} \t\t\t\t\tbreak; \t\t\t\t} \t\t} \t}  \tprivate void OnGUI() \t{ \t\tGUI.Box(buyMenu, &quot;Buying menu&quot;); \/\/\u0414\u0435\u043b\u0430\u0435\u043c \u0433\u0443\u0435\u0432\u0441\u043a\u0438\u0439 \u0431\u043e\u043a\u0441 \u043d\u0430 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0435 buyMenu \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u043c, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c \u043c\u0435\u0436\u0434\u0443 &quot;&quot; \t\tif (GUI.Button(firstTower, &quot;Plasma Tower\\n&quot; + (int)TowerPrices.Plasma + &quot;$&quot;)) \/\/\u0435\u0441\u043b\u0438 \u0438\u0434\u0451\u0442 \u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u043d\u0430 \u043f\u0435\u0440\u0432\u0443\u044e \u043a\u043d\u043e\u043f\u043a\u0443 \t\t{ \t\t\tif (GlobalVars.PlayerMoney &gt;= (int)TowerPrices.Plasma) \/\/\u0435\u0441\u043b\u0438 \u0443 \u0438\u0433\u0440\u043e\u043a\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0435\u043d\u0435\u0433 \t\t\t\tGlobalVars.mau5tate = GlobalVars.ClickState.Placing; \/\/\u043c\u0435\u043d\u044f\u0435\u043c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u044b\u0448\u0438 \u043d\u0430 &quot;\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0443\u0448\u043a\u0438&quot; \t\t} \t\tif (GUI.Button(secondTower, &quot;Pulse Tower\\n&quot; + (int)TowerPrices.Pulse + &quot;$&quot;)) \/\/\u0441 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \t\t{ \t\t\t\/\/action here \t\t} \t\tif (GUI.Button(thirdTower, &quot;Beam Tower\\n&quot; + (int)TowerPrices.Beam + &quot;$&quot;)) \t\t{ \t\t\t\/\/action here \t\t} \t\tif (GUI.Button(fourthTower, &quot;Tesla Tower\\n&quot; + (int)TowerPrices.Tesla + &quot;$&quot;)) \t\t{ \t\t\t\/\/action here \t\t} \t\tif (GUI.Button(fifthTower, &quot;Artillery Tower\\n&quot; + (int)TowerPrices.Artillery + &quot;$&quot;)) \t\t{ \t\t\t\/\/action here \t\t}  \t\tGUI.Box(playerStats, &quot;Player Stats&quot;); \t\tGUI.Label(playerStatsPlayerMoney, &quot;Money: &quot; + GlobalVars.PlayerMoney + &quot;$&quot;);  \t\tGUI.Box(towerMenu, &quot;Tower menu&quot;); \t\tif (GUI.Button(towerMenuSellTower, &quot;Sell&quot;)) \t\t{ \t\t\t\/\/action here \t\t} \t\tif (GUI.Button(towerMenuUpgradeTower, &quot;Upgrade&quot;)) \t\t{ \t\t\t\/\/if (GlobalVars.mau5tate == GlobalVars.ClickState.Default) \t\t\t\/\/{ \t\t\t\/\/\tGlobalVars.mau5tate = GlobalVars.ClickState.Upgrading; \t\t\t\/\/} \t\t} \t}  \t\/\/\u0446\u0435\u043d\u044b \u043d\u0430 \u043f\u0443\u0448\u043a\u0438 \tprivate enum TowerPrices \t{ \t\tPlasma = 100, \t\tPulse = 150, \t\tBeam = 250, \t\tTesla = 300, \t\tArtillery = 350 \t} } <\/code><\/pre>\n<p>  <b>MobHP.cs<\/b>  <\/p>\n<pre><code class=\"cs\">using UnityEngine;  public class MobHP : MonoBehaviour { \tpublic float maxHP = 100; \/\/\u041c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u0425\u041f \tpublic float curHP = 100; \/\/\u0422\u0435\u043a\u0443\u0449\u0435\u0435 \u0425\u041f \tpublic Color MaxDamageColor = Color.red; \/\/\u0446\u0432\u0435\u0442\u0430 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u0431\u0438\u0442\u043e\u0433\u043e \tpublic Color MinDamageColor = Color.blue; \/\/\u0438 \u0446\u0435\u043b\u043e\u0433\u043e \u043c\u043e\u0431\u0430 \tpublic GameObject explosionPrefab;  \tprivate void Awake() \t{ \t\tGlobalVars.MobList.Add(gameObject); \/\/\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0435\u0431\u044f \u0432 \u043e\u0431\u0449\u0438\u0439 \u043b\u0438\u0441\u0442 \u043c\u043e\u0431\u043e\u0432 \t\tGlobalVars.MobCount++; \/\/\u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u043c\u043e\u0431\u043e\u0432 \t\tif (maxHP &lt; 1) maxHP = 1; \/\/\u0435\u0441\u043b\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0445\u043f \u0437\u0430\u0434\u0430\u043d\u043e \u043c\u0435\u043d\u0435\u0435 \u0435\u0434\u0438\u043d\u0438\u0446\u044b - \u0441\u0442\u0430\u0432\u0438\u043c \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \t}  \tpublic void ChangeHP(float adjust) \/\/\u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0425\u041f \u043c\u043e\u0431\u0430 \t{ \t\tif ((curHP + adjust) &gt; maxHP) curHP = maxHP;\/\/\u0435\u0441\u043b\u0438 \u0441\u0443\u043c\u043c\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0425\u041f \u0438 adjust \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0431\u043e\u043b\u0435\u0435, \u0447\u0435\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0445\u043f - \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0425\u041f \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0440\u0430\u0432\u043d\u044b\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \t\telse curHP += adjust; \/\/\u0438\u043d\u0430\u0447\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c adjust \t}  \tprivate void Update() \t{ \t\tgameObject.renderer.material.color = Color.Lerp(MaxDamageColor, MinDamageColor, curHP \/ maxHP); \/\/\u041b\u0435\u0440\u043f\u0438\u043c \u0446\u0432\u0435\u0442 \u043c\u043e\u0431\u0430 \u043f\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0446\u0432\u0435\u0442\u0430\u043c. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435: \u043a\u0440\u0430\u0441\u043d\u044b\u0439 - \u043c\u043e\u0431 \u043f\u043e\u0447\u0442\u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u0431\u0438\u0442, \u0441\u0438\u043d\u0438\u0439 - \u0446\u0435\u043b\u044b\u0439. \t\tif (curHP &lt;= 0) \/\/\u0435\u0441\u043b\u0438 \u0425\u041f \u0443\u043f\u0430\u043b\u043e \u0432 \u043d\u043e\u043b\u044c \u0438\u043b\u0438 \u043d\u0438\u0436\u0435 \t\t{ \t\t\tMobAI mai = gameObject.GetComponent&lt;MobAI&gt;(); \/\/\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443 AI \u043c\u043e\u0431\u0430 \t\t\tif (mai != null) \t\t\t{ \t\t\t\tGlobalVars.PlayerMoney += mai.mobPrice; \/\/\u0435\u0441\u043b\u0438 \u043e\u043d \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 - \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0435\u043d\u0435\u0433 \u0438\u0433\u0440\u043e\u043a\u0443 \u0432 \u0440\u0430\u0437\u043c\u0435\u0440\u0435 \u0446\u0435\u043d\u044b \u0437\u0430 \u0433\u043e\u043b\u043e\u0432\u0443 \u043c\u043e\u0431\u0430 \t\t\t}  \t\t\tif (explosionPrefab != null) \t\t\t{ \t\t\t\tInstantiate(explosionPrefab, gameObject.transform.position, Quaternion.identity); \t\t\t}  \t\t\tDestroy(gameObject); \/\/\u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0435\u0431\u044f \t\t} \t}  \tprivate void OnDestroy() \/\/\u043f\u0440\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \t{ \t\tGlobalVars.MobList.Remove(gameObject); \/\/\u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0435\u0431\u044f \u0438\u0437 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u043c\u043e\u0431\u043e\u0432 \t\tGlobalVars.MobCount--; \/\/\u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u043c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u043c\u043e\u0431\u043e\u0432 \u043d\u0430 1 \t} } <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0440\u0435\u0437\u0430\u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0438 \u0435\u0451 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u0432 \u043a\u043e\u0434\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c.<br \/>  <b>MobAI.cs<\/b>  <\/p>\n<pre><code class=\"cs\">using UnityEngine;  public class MobAI : MonoBehaviour { \tpublic GameObject Target; \/\/\u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0446\u0435\u043b\u044c  \tpublic float mobPrice = 5.0f; \/\/\u0446\u0435\u043d\u0430 \u0437\u0430 \u0443\u0431\u0438\u0439\u0441\u0442\u0432\u043e \u043c\u043e\u0431\u0430 \tpublic float mobMinSpeed = 0.5f; \/\/\u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043c\u043e\u0431\u0430 \tpublic float mobMaxSpeed = 2.0f; \/\/\u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043c\u043e\u0431\u0430 \tpublic float mobRotationSpeed = 2.5f; \/\/\u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043f\u043e\u0432\u043e\u0440\u043e\u0442\u0430 \u043c\u043e\u0431\u0430 \tpublic float attackDistance = 5.0f; \/\/\u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u044f \u0430\u0442\u0430\u043a\u0438 \tpublic float damage = 5; \/\/\u0443\u0440\u043e\u043d, \u043d\u0430\u043d\u043e\u0441\u0438\u043c\u044b\u0439 \u043c\u043e\u0431\u043e\u043c \tpublic float attackTimer = 0.0f; \/\/\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 \u043c\u0435\u0436\u0434\u0443 \u0443\u0434\u0430\u0440\u0430\u043c\u0438 \tpublic const float coolDown = 2.0f; \/\/\u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u0431\u0440\u043e\u0441\u0430 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0430\u0442\u0430\u043a\u0438 \u0432 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435  \tpublic float MobCurrentSpeed; \/\/\u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043c\u043e\u0431\u0430, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0437\u0436\u0435 \tprivate Transform mob; \/\/\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430 \u043c\u043e\u0431\u0430  \tprivate void Awake() \t{ \t\tmob = transform; \/\/\u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c \u043c\u043e\u0431\u0430 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e (\u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c) \t\tMobCurrentSpeed = Random.Range(mobMinSpeed, mobMaxSpeed); \/\/\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0440\u0430\u043d\u0434\u043e\u043c\u0430 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \t}  \tprivate void Update() \t{ \t\tif (Target != null) \/\/\u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0446\u0435\u043b\u044c \t\t{ \t\t\tmob.rotation = Quaternion.Lerp(mob.rotation, Quaternion.LookRotation(new Vector3(Target.transform.position.x, 0.0f, Target.transform.position.z) - new Vector3(mob.position.x, 0.0f, mob.position.z)), mobRotationSpeed); \/\/\u0438\u0437\u0431\u0443\u0448\u043a\u0430-\u0438\u0437\u0431\u0443\u0448\u043a\u0430, \u043f\u043e\u0432\u0435\u0440\u043d\u0438\u0441\u044c \u043a \u043f\u0443\u0448\u043a\u0435 \u043f\u0435\u0440\u0435\u0434\u043e\u043c! \t\t\tmob.position += mob.forward * MobCurrentSpeed * Time.deltaTime; \/\/\u0434\u0432\u0438\u0433\u0430\u0435\u043c \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443, \u043a\u0443\u0434\u0430 \u0441\u043c\u043e\u0442\u0440\u0438\u0442 \u043c\u043e\u0431 \t\t\tfloat squaredDistance = (Target.transform.position - mob.position).sqrMagnitude; \/\/\u043c\u0435\u0440\u044f\u0435\u043c \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u044e \u0434\u043e \u0446\u0435\u043b\u0438 \t\t\tVector3 structDirection = (Target.transform.position - mob.position).normalized; \/\/\u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0435\u043a\u0442\u043e\u0440 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \t\t\tfloat attackDirection = Vector3.Dot(structDirection, mob.forward); \/\/\u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0435\u043a\u0442\u043e\u0440 \u0430\u0442\u0430\u043a\u0438 \t\t\tif (squaredDistance &lt; attackDistance * attackDistance && attackDirection &gt; 0) \/\/\u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0430 \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u0438 \u0430\u0442\u0430\u043a\u0438 \u0438 \u0446\u0435\u043b\u044c \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \t\t\t{ \t\t\t\tif (attackTimer &gt; 0) attackTimer -= Time.deltaTime; \/\/\u0435\u0441\u043b\u0438 \u0442\u0430\u0439\u043c\u0435\u0440 \u0430\u0442\u0430\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 0 - \u043e\u0442\u043d\u0438\u043c\u0430\u0435\u043c \u0435\u0433\u043e \t\t\t\tif (attackTimer &lt;= 0) \/\/\u0435\u0441\u043b\u0438 \u0436\u0435 \u043e\u043d \u0441\u0442\u0430\u043b \u043c\u0435\u043d\u044c\u0448\u0435 \u043d\u0443\u043b\u044f \u0438\u043b\u0438 \u0440\u0430\u0432\u0435\u043d \u0435\u043c\u0443 \t\t\t\t{ \t\t\t\t\tBaseHP bhp = Target.GetComponent&lt;BaseHP&gt;(); \/\/\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443 \u0425\u041f \u0446\u0435\u043b\u0438 \t\t\t\t\tif (bhp != null) bhp.ChangeHP(-damage); \/\/\u0435\u0441\u043b\u0438 \u0446\u0435\u043b\u044c \u0435\u0449\u0451 \u0436\u0438\u0432\u0430\u044f, \u043d\u0430\u043d\u043e\u0441\u0438\u043c \u0443\u0440\u043e\u043d (\u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0435 \u043e\u0434\u043d\u0438 \u0431\u0438\u0442\u044c \u043f\u043e \u0446\u0435\u043b\u0438, \u043f\u043e\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430) \t\t\t\t\tattackTimer = coolDown; \/\/\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0442\u0430\u0439\u043c\u0435\u0440 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \t\t\t\t\tMobHP mhp = GetComponent&lt;MobHP&gt;(); \t\t\t\t\tmhp.curHP = 0; \t\t\t\t} \t\t\t} \t\t} \t\telse \t\t{ \t\t\tGameObject baza = GameObject.FindGameObjectWithTag(&quot;Base&quot;); \/\/\u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043d\u0430\u0448 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0431\u0430\u0437\u043e\u0439, \u043e\u043d \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \t\t\tif (baza != null) Target = baza; \t\t} \t} } <\/code><\/pre>\n<p>  <b>BaseHP.cs<\/b>  <\/p>\n<pre><code class=\"cs\">using UnityEngine;  public class BaseHP : MonoBehaviour { \tpublic float maxHP = 1000; \tpublic float curHP = 1000; \tpublic const float regenerationDelayConstant = 2.5f; \/\/\u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 \u043c\u0435\u0436\u0434\u0443 \u0440\u0435\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0435\u0439 \u0445\u043f \u0431\u0430\u0437\u044b \tpublic float regenarationDelayVariable = 2.5f; \/\/\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0442\u043e\u0439 \u0436\u0435 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 \tpublic float regenerationAmount = 10.0f; \/\/\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u0445\u043f \u043f\u0440\u0438 \u0440\u0435\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0437\u0430 \u0440\u0430\u0437  \tprivate void Awake() \t{ \t\tif (maxHP &lt; 1) maxHP = 1; \t}  \tpublic void ChangeHP(float adjust) \t{ \t\tif ((curHP + adjust) &gt; maxHP) curHP = maxHP; \t\telse curHP += adjust; \t\tif (curHP &gt; maxHP) curHP = maxHP; \/\/just in case \t}  \tprivate void Update() \t{ \t\tif (curHP &lt;= 0) \t\t{ \t\t\tDestroy(gameObject); \t\t} \t\telse \t\t{ \t\t\tif (regenarationDelayVariable &gt; 0) regenarationDelayVariable -= Time.deltaTime; \/\/\u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 \u0431\u043e\u043b\u0435\u0435 \u043d\u0443\u043b\u044f - \u043e\u0442\u043d\u0438\u043c\u0430\u0435\u043c \u043e\u0442 \u043d\u0435\u0451 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \t\t\tif (regenarationDelayVariable &lt;= 0) \/\/\u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0441\u0442\u0430\u043b\u0430 \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u0430 \u043d\u0443\u043b\u044e \t\t\t{ \t\t\t\tChangeHP(regenerationAmount); \/\/\u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0440\u0430\u043d\u0435\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0425\u041f \t\t\t\tregenarationDelayVariable = regenerationDelayConstant; \/\/\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043d\u0430\u0448\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0432 \u0435\u0451 \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \t\t\t} \t\t} \t}  \tprivate void OnGUI() \t{ \t\tVector3 screenPosition = Camera.main.WorldToScreenPoint(gameObject.transform.position); \/\/\u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0438\u0440\u0430 \t\tVector3 cameraRelative = Camera.main.transform.InverseTransformPoint(transform.position); \/\/\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043e\u0442 \u043a\u0430\u043c\u0435\u0440\u044b \t\tif (cameraRelative.z &gt; 0) \/\/\u0435\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u043f\u0435\u0440\u0435\u0434\u0438 \u043a\u0430\u043c\u0435\u0440\u044b \t\t{ \t\t\t\/\/\u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0435\u0433\u043e HP \t\t\tif (curHP &gt; 0) GUI.Label(new Rect(screenPosition.x, Screen.height - screenPosition.y, 200f, 20f), curHP.ToString()); \t\t} \t} } <\/code><\/pre>\n<p>  <b>SpawnerAI.cs<\/b>  <\/p>\n<pre><code class=\"cs\">using UnityEngine;  public class SpawnerAI : MonoBehaviour { \tpublic int waveAmount = 5; \/\/\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0431\u043e\u0432 \u0437\u0430 1 \u0432\u043e\u043b\u043d\u0443 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0435 \u0441\u043f\u0430\u0443\u043d\u0430 \tpublic int waveNumber = 0; \/\/\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0432\u043e\u043b\u043d\u044b \tpublic float waveDelayTimer = 30.0F; \/\/\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0441\u043f\u0430\u0443\u043d\u0430 \u0432\u043e\u043b\u043d\u044b \tpublic float waveCooldown = 20.0F; \/\/\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f (\u043d\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430 \u0443\u0436\u0435!) \u0434\u043b\u044f \u0441\u0431\u0440\u043e\u0441\u0430 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0432\u044b\u0448\u0435, \u043c\u044b \u0435\u0451 \u0431\u0443\u0434\u0435\u043c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \tpublic int maximumWaves = 500; \/\/\u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0431\u043e\u0432 \u0432 \u0438\u0433\u0440\u0435 \tpublic Transform Mob; \/\/\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0440\u0435\u0444\u0430\u0431\u0430 \u0432 Unity \tpublic GameObject[] SpawnPoints; \/\/\u043c\u0430\u0441\u0441\u0438\u0432 \u0442\u043e\u0447\u0435\u043a \u0441\u043f\u0430\u0443\u043d\u0430  \tprivate void Awake() \t{ \t\tSpawnPoints = GameObject.FindGameObjectsWithTag(&quot;Spawnpoint&quot;); \/\/\u0437\u0430\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0442\u043e\u0447\u043a\u0438 \u0441\u043f\u0430\u0443\u043d\u0430 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \t}  \tprivate void Update() \t{ \t\tif (waveDelayTimer &gt; 0) \/\/\u0435\u0441\u043b\u0438 \u0442\u0430\u0439\u043c\u0435h \u0441\u043f\u0430\u0443\u043d\u0430 \u0432\u043e\u043b\u043d\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0443\u043b\u044f \t\t{ \t\t\tif (GlobalVars.MobCount == 0) waveDelayTimer = 0; \/\/\u0435\u0441\u043b\u0438 \u043c\u043e\u0431\u043e\u0432 \u043d\u0430 \u0441\u0446\u0435\u043d\u0435 \u043d\u0435\u0442 - \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u043d\u043e\u043b\u044c \t\t\telse waveDelayTimer -= Time.deltaTime; \/\/\u0438\u043d\u0430\u0447\u0435 \u043e\u0442\u043d\u0438\u043c\u0430\u0435\u043c \u0442\u0430\u0439\u043c\u0435\u0440 \t\t} \t\tif (waveDelayTimer &lt;= 0) \/\/\u0435\u0441\u043b\u0438 \u0442\u0430\u0439\u043c\u0435\u0440 \u043c\u0435\u043d\u0435\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u0435\u043d \u043d\u0443\u043b\u044e \t\t{ \t\t\tif (SpawnPoints != null && waveNumber &lt; maximumWaves) \/\/\u0435\u0441\u043b\u0438 \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u0442\u043e\u0447\u043a\u0438 \u0441\u043f\u0430\u0443\u043d\u0430 \u0438 \u0435\u0449\u0451 \u043d\u0435 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442 \u043f\u0440\u0435\u0434\u0435\u043b \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0432\u043e\u043b\u043d \t\t\t{ \t\t\t\tforeach (GameObject spawnPoint in SpawnPoints) \/\/\u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0435 \u0441\u043f\u0430\u0443\u043d\u0430 \t\t\t\t{ \t\t\t\t\tfor (int i = 0; i &lt; waveAmount; i++) \/\/\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c i \u043a\u0430\u043a \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u0441\u043f\u0430\u0443\u043d\u0430, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0431\u044b \u043d\u0435 \u0431\u044b\u043b\u0438 \u0432 \u0443\u043f\u043e\u0440 \u0434\u0440\u0443\u0433 \u043a \u0434\u0440\u0443\u0433\u0443 \t\t\t\t\t{ \t\t\t\t\t\tInstantiate(Mob, new Vector3(spawnPoint.transform.position.x, spawnPoint.transform.position.y, spawnPoint.transform.position.z + i * 10), Quaternion.identity); \/\/\u0441\u043f\u0430\u0443\u043d\u0438\u043c \u043c\u043e\u0431\u0430 \t\t\t\t\t}  \t\t\t\t\tif (waveCooldown &gt; 5.0f) \/\/\u0435\u0441\u043b\u0438 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u0434\u043b\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 5 \u0441\u0435\u043a\u0443\u043d\u0434 \t\t\t\t\t{ \t\t\t\t\t\twaveCooldown -= 0.1f; \/\/\u0441\u043e\u043a\u0440\u0430\u0449\u0430\u0435\u043c \u043d\u0430 0.1 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \t\t\t\t\t\twaveDelayTimer = waveCooldown; \/\/\u0437\u0430\u0434\u0430\u0451\u043c \u043d\u043e\u0432\u044b\u0439 \u0442\u0430\u0439\u043c\u0435\u0440 \t\t\t\t\t} \t\t\t\t\telse \/\/\u0438\u043d\u0430\u0447\u0435 \t\t\t\t\t{ \t\t\t\t\t\twaveCooldown = 5.0f; \/\/\u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u043d\u0435\u0435 5 \u0441\u0435\u043a\u0443\u043d\u0434 \t\t\t\t\t\twaveDelayTimer = waveCooldown; \t\t\t\t\t}  \t\t\t\t\tif (waveNumber &gt;= 50) \/\/\u043f\u043e\u0441\u043b\u0435 50 \u0432\u043e\u043b\u043d\u044b \t\t\t\t\t{ \t\t\t\t\t\twaveAmount = 10; \/\/\u0431\u0443\u0434\u0435\u043c \u0441\u043f\u0430\u0443\u043d\u0438\u0442\u044c \u043f\u043e 10 \u043c\u043e\u0431\u043e\u0432 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0435 \t\t\t\t\t} \t\t\t\t} \t\t\t\twaveNumber++; \/\/\u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u043d\u043e\u043c\u0435\u0440 \u0432\u043e\u043b\u043d\u044b \t\t\t} \t\t} \t} } <\/code><\/pre>\n<p>  <b>TurretHP.cs<\/b>  <\/p>\n<pre><code class=\"cs\">using UnityEngine;  public class TurretHP : MonoBehaviour { \tpublic float maxHP = 100; \/\/\u041c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u0425\u041f \tpublic float curHP = 100; \/\/\u0422\u0435\u043a\u0443\u0449\u0435\u0435 \u0425\u041f  \tprivate void Awake() \t{ \t\tGlobalVars.TurretList.Add(gameObject); \t\tGlobalVars.TurretCount++; \t\tif (maxHP &lt; 1) maxHP = 1; \t}  \tpublic void ChangeHP(float adjust) \t{ \t\tif ((curHP + adjust) &gt; maxHP) curHP = maxHP; \t\telse curHP += adjust; \t\tif (curHP &gt; maxHP) curHP = maxHP; \t}  \tprivate void Update() \t{ \t\tif (curHP &lt;= 0) \t\t{ \t\t\tDestroy(gameObject); \t\t} \t}  \tprivate void OnDestroy() \t{ \t\tGlobalVars.TurretList.Remove(gameObject); \t\tGlobalVars.TurretCount--; \t} } <\/code><\/pre>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u0437\u0430\u043c\u0435\u043d\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u0431\u043e\u043d\u0443\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442 \u0436\u0438\u0437\u043d\u044c \u043f\u0440\u0438 \u0440\u0435\u0433\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0435 \u0434\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0430\u0442\u0430\u043a\u0438 \u043a\u0430\u043a \u043f\u0443\u0448\u043a\u0430\u043c, \u0442\u0430\u043a \u0438 \u043c\u043e\u0431\u0430\u043c:<\/p>\n<p>  <b>myGizmos.cs<\/b>  <\/p>\n<pre><code class=\"cs\">using UnityEngine;  public static class myGizmos { \tpublic static void DrawCircle(Vector3 pos, Vector3 normal, int segs, float radius, bool showNormal) \t{ \t\tfloat stepAng = 360.0f \/ Mathf.Max(segs, 1.0f); \t\tfloat curAng = stepAng; \t\tQuaternion rot = Quaternion.FromToRotation(Vector3.up, normal);  \t\twhile (curAng &lt;= 360.0f) \t\t{ \t\t\tVector3 pPrev = rot * (Quaternion.Euler(Vector3.up * (curAng - stepAng)) * (Vector3.right * radius)); \t\t\tVector3 p = rot * (Quaternion.Euler(Vector3.up * curAng) * (Vector3.right * radius));  \t\t\tGizmos.DrawLine(pos + pPrev, pos + p);  \t\t\tcurAng += stepAng; \t\t}  \t\tGizmos.DrawWireSphere(pos, radius * 0.1f);  \t\tif (showNormal) Gizmos.DrawLine(pos, pos + normal * radius); \t}  \tpublic static void DrawArrow(Vector3 pos, Vector3 dir, Vector2 size) \t{ \t\tGizmos.DrawWireSphere(pos, size.x);  \t\tVector3 endPos = pos + dir * size.y;  \t\tGizmos.DrawLine(pos, endPos);  \t\tVector3 ax1 = Vector3.Cross(dir, Vector3.right); \t\tVector3 ax2 = Vector3.Cross(dir, Vector3.forward);  \t\tVector3 hpB = endPos - (dir * size.y * 0.2f); \t\tVector3 hp1 = hpB + ax1 * size.x; \t\tVector3 hp2 = hpB - ax1 * size.x; \t\tVector3 hp3 = hpB + ax2 * size.x; \t\tVector3 hp4 = hpB - ax2 * size.x;  \t\tGizmos.DrawLine(endPos, hp1); \t\tGizmos.DrawLine(endPos, hp2); \t\tGizmos.DrawLine(endPos, hp3); \t\tGizmos.DrawLine(endPos, hp4);  \t\tGizmos.DrawLine(hp1, hp4); \t\tGizmos.DrawLine(hp1, hp3); \t\tGizmos.DrawLine(hp2, hp4); \t\tGizmos.DrawLine(hp2, hp3); \t} } <\/code><\/pre>\n<p>  <b>GizmoOnObject.cs<\/b>  <\/p>\n<pre><code class=\"cs\">using UnityEngine;  public class GizmoOnObject : MonoBehaviour { \tpublic Color GizmoColor = Color.yellow; \tpublic float GizmoRadius = 40.0f; \tpublic int GizmoSegments = 36; \tpublic bool ShowNormal;  \tpublic void OnDrawGizmosSelected() \t{ \t\tGizmos.color = GizmoColor; \t\tmyGizmos.DrawCircle(transform.position, Vector3.up, GizmoSegments, GizmoRadius, ShowNormal); \t} } <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c: \u043d\u0430\u0434\u0435\u0432\u0430\u0435\u0442\u0435 \u0441\u043a\u0440\u0438\u043f\u0442 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u0432 \u0438\u043d\u0441\u043f\u0435\u043a\u0442\u043e\u0440\u0435 \u0440\u0435\u0433\u0443\u043b\u0438\u0440\u0443\u0435\u0442\u0435 \u0434\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c. \u0412\u043e\u043a\u0440\u0443\u0433 \u0413\u041e \u043f\u0440\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0436\u0435\u043b\u0442\u044b\u0439 \u043a\u0440\u0443\u0433, \u044d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0430\u044f \u0434\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/p>\n<h5>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h5>\n<p>  \u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u0441\u044f\u043a\u0438 \u0432 \u043a\u043e\u0434\u0435, \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u043f\u043e\u043b\u043d\u0435 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f \u0438\u0433\u0440\u044b. \u042f \u0442\u0430\u043a \u0438 \u043d\u0435 \u0443\u0441\u043f\u0435\u043b \u043f\u043e\u043a\u043e\u0432\u044b\u0440\u044f\u0442\u044c\u0441\u044f \u0441 NavMesh, \u043d\u043e \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u2014 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e.<\/p>\n<p>  \u041f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445, \u043a\u0430\u043a\u0438\u0435 \u0435\u0449\u0451 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0432\u0430\u043c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u0447\u0430\u0441\u0442\u0438.<\/p>\n<p>  \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442\u2026    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/182672\/\"> http:\/\/habrahabr.ru\/post\/182672\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435! \u0412\u0435\u0441\u044c\u043c\u0430 \u043d\u0430\u0434\u043e\u043b\u0433\u043e \u0443 \u043c\u0435\u043d\u044f \u0440\u0430\u0441\u0442\u044f\u043d\u0443\u043b\u0430\u0441\u044c \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 (\u0436\u0438\u0437\u043d\u044c \u0434\u0430\u0432\u0430\u043b\u0430 \u0438\u0437\u0440\u044f\u0434\u043d\u044b\u0445 \u043f\u0438\u043d\u043a\u043e\u0432 \u043f\u043e\u0434 \u0437\u0430\u0434), \u043d\u043e \u0432\u043e\u0442 \u044f \u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0441\u044f \u0438 \u0433\u043e\u0442\u043e\u0432 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0441 \u0432\u0430\u043c\u0438.<\/p>\n<p>  <a href=\"http:\/\/habrahabr.ru\/post\/148410\/\">\u0427\u0430\u0441\u0442\u044c \u043f\u0435\u0440\u0432\u0430\u044f<\/a><\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/dc7\/d6b\/d5a\/dc7d6bd5a92268e9e9e4f1b1ff9af2c8.png\"\/><br \/>  <i>\u041d\u0435\u0443\u0434\u0430\u0447\u043d\u044b\u0439 \u0442\u0435\u0441\u0442 \u0444\u0438\u0437\u0438\u043a\u0438<\/i><\/p>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b:<br \/>   \u2014 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u0434 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438;<br \/>   \u2014 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u00ab\u0431\u0430\u0437\u0430\u00bb \u0438 \u043d\u0430\u0443\u0447\u0438\u043c \u0435\u0451 \u0447\u0438\u043d\u0438\u0442\u044c\u0441\u044f \u0432\u0440\u0435\u043c\u044f \u043e\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438;<br \/>   \u2014 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0443\u0448\u043a\u0430\u043c \u043f\u0430\u0442\u0440\u043e\u043d\u044b \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u0440\u044f\u0434\u043a\u0443;<br \/>   \u2014 \u0438\u0437\u0431\u0430\u0432\u0438\u043c\u0441\u044f \u043e\u0442 \u00ab\u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e\u0439\u00bb \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 gv;<\/p>\n<p>  \u0410 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0432\u0430\u0441 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u0431\u043e\u043d\u0443\u0441 \ud83d\ude42<\/p>\n<p>  \u0412\u0441\u0435\u043c \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u0432\u0448\u0438\u043c\u0441\u044f \u2014 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u0434\u043e\u043b\u0433\u043e\u0436\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u0442!  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-182672","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/182672","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=182672"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/182672\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=182672"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=182672"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=182672"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}