ãUnityã2Dã¿ã¤ã«ããã⧠Isometricãªãã£ã¼ã«ãã§é段ãç»ã
Unity 2020.2.1f1 Personal(2021å¹´3æ)
前回ã®ç¶ãã§ãã
ä»åã¯ãã¬ã¤ã¤ã¼ã«é段ãç»ããã¾ãã
Cell LayoutãIsometric Z as Yã®å ´åããã¬ã¤ã¤ã¼ã®é«ãã¯position.zã§æ±ºã¾ãã¨åå解説ãã¾ããã
ä»åã¯é段ã®éä¸ã§ãã¬ã¤ã¤ã¼ã®position.zãåçã«å¤æ´ããæ©è½ãæè¼ãã
ãã¬ã¤ã¤ã¼ã«é段ãç»ããã¦ããã¾ãã
é段ã®Tileãä½æ
ã¾ãã¯é段ã®Tileãä½æãã¦ããã¾ãã
ãã¡ãã®ç»åãã使ç¨ä¸ããã
stone_stair.png
Spriteã®InspectorããPixel per Unitã32ãFilter ModeãPoint(no filter)ã«è¨å®ãã¾ãã
ã¾ãSprite Editorã«ã¦Pivotã®ä½ç½®ãCustomã«ãX:0.5, Y:0.25ã«è¨å®ãã¾ãã
ã¾ãCustom Physics Shapeã«ã¦é段ã®éãé以å¤ã®é¨åãæ åããã¾ãã
Custom Physics Shapeã®è¨å®
ä¸è¨ã®è¨å®ã¯前回ã¾ã§ã®2Dã¿ã¤ã«ãããã®è¨äºã§ä½åº¦ãè¡ã£ã¦ã¾ãã®ã§ã
ä¸æç¹ã¯éå»è¨äºããåç
§ãã¦é ããã°ã¨æãã¾ãã
Spriteã®è¨å®ãå®äºãã¾ãããTilePaletteã«stone_stairãç»é²ãã¦ä¸ããã
stone_stairãç»é²
以ä¸ã§é段Tileã®è¨å®ã¯çµäºã§ãã
Tileãé ç½®ãã
ç¶ãã¦Tileãé
ç½®ãã¦ããã¾ãã
Tilemapã®Cell LayoutãIsometric Z as Yã§ããå ´åã
TilePaletteã®Position Zã®å¤ã§é
ç½®ããTileã®é«ããå¤ãããã¾ãã
ã¾ãã¯Position Z:0ã§è¶³å ´ãä½æãã¾ãã
Tile Palette Z Position:0
è¶³å ´ä½æ
ãã®è¦é ã§Z Position:2, 4, 6ã«å¤æ´ããªããé段ãä½æãã¦ããã¾ãã
Z Position: 2
Z Positision: 4
Z Position: 6
以ä¸ã§Tileã®é ç½®ã¯çµäºã§ãã
ãã¬ã¤ã¤ã¼ã®é«ã(position.z)ãåçã«å¤æ´(Playerãªãã¸ã§ã¯ã)
æå¾ã«é段ãç»ãéä¸ã§ãã¬ã¤ã¤ã¼ã®é«ããå¤æ´ããã¦ããã¾ãã
ã¾ãã¯Playerãªãã¸ã§ã¯ãã®TagããPlayerãã«å¤æ´ãã¾ãã
å¾ã»ã©OnTriggerEnter2Dã¡ã½ããã®ä¸ã§ãã¡ãã®Tagã¯æ´»ç¨ãã¾ãã
ç¶ãã¦Playerãªãã¸ã§ã¯ãã«ãTriggerãã¨ããååã®åãªãã¸ã§ã¯ããä½æãã¾ãã
Hierarchyä¸ã§Playerãªãã¸ã§ã¯ããé¸æããç¶æ
ã§å³ã¯ãªãã¯ãCreate Emptyã§ä½æãã¾ãã
Playerãªãã¸ã§ã¯ãã®åãªãã¸ã§ã¯ã(åå:Trigger)ãä½æ
ãã¡ãã«Circle Collder2Dã³ã³ãã¼ãã³ããã¨ãã¤ããIs Triggerãtrueã«ãã
Colliderããã£ã©ã¯ã¿ã¼ã®ä¸å¤®ã«æ¥ãããã«Offsetã¨Radiusãè¨å®ãã¾ãã
Triggerãªãã¸ã§ã¯ãã®Circle Collider2Dè¨å®
以ä¸ã§Playerãªãã¸ã§ã¯ãã®è¨å®ã¯å®äºã§ãã
ãã¬ã¤ã¤ã¼ã®é«ã(position.z)ãåçã«å¤æ´(StairPointãªãã¸ã§ã¯ã)
ç¶ãã¦ãã¬ã¤ã¤ã¼ã®é«ããå¤æ´ãããã¤ã³ãã§ããStairPointãªãã¸ã§ã¯ããä½æãã¾ãã
Hierachyã®Create Emptyã§StairPointã¨ããååã®ç©ºãªãã¸ã§ã¯ããä½æãã¾ãã
StairPointã®å ´æãåãããããããã«Iconãã¤ãã¾ãã
StairPointã«CircleCollider2Dãã¤ããIsTriggerãOffsetãRadiusã以ä¸ã®ããã«è¨å®ãã¾ãã
以ä¸ã®è¨å®ã§StairPointãªãã¸ã§ã¯ããPlayerãªãã¸ã§ã¯ããééããæã«ã
OnTriggerEnter2Dãå®è¡ãããããã«ãªãã¾ããã
StairPoint.csã¨ããScriptãæ°è¦ä½æããStairPointãªãã¸ã§ã¯ãã«è¨å®ãã¾ãã
using System.Collections; using System.Collections.Generic; using UnityEngine; public class StairPoint : MonoBehaviour { [SerializeField] float zPos; private void OnTriggerEnter2D(Collider2D collision) { if (collision.transform.tag == "Player") { collision.transform.position = new Vector3(collision.transform.position.x, collision.transform.position.y, zPos); } } }
StairPoint.cs
ã¿ã°ãPlayerã¨ãããªãã¸ã§ã¯ãã®Triggerã«ã¶ã¤ãã£ãæã
ãã®ãªãã¸ã§ã¯ãã®position.zãzPosã«å¤æ´ããã ãã®Scriptã§ãã
zPosã¯Inspectorä¸ã§è¨å®ã§ãã¾ãã
StairPointã¯ãã®ãã¨è¤æ°ä½¿ãã®ã§Prefabåãã¦ããã¾ãããã
Projectãã¥ã¼ã«ãã©ãã°&ããããã§Prefabå
ããã§ã¯StairPointãé
ç½®ãã¦ããã¾ãã
æåã®StairPointã®zPosã¯2ã«è¨å®ã
é段ã®å ¥ãå£ã«é ç½®ãã¾ãã
次ã®StairPointã®ä½ç½®ããã¯Playerãªãã¸ã§ã¯ãã移åããã¦äººåã§ä½ç½®ãæ¢ãã¾ãã
Playerãªãã¸ã§ã¯ãã®position.zã2ã«ãã¦ãããé段ã®ä¸ããä¸ã¸ç§»åãããPlayerãªãã¸ã§ã¯ããé段ã«é ããä½ç½®ã«2çªç®ã®StairPointãªãã¸ã§ã¯ããé
ç½®ãã¾ãã
é
ç½®ããStairPointã®zPosã¯4ã«ãã¦ããã¾ãã
ããã§é ããã®ã§
zPosã4ã«ããStairPointãé
ç½®
3çªç®ã®StairPointã®é
ç½®ãåãè¦é ã§ãã
Playerãªãã¸ã§ã¯ãã®position.zã4ã«ãã¦ããé段ãä¸ããä¸ã¸ç§»åã
Playerãé ããä½ç½®ã«zPosã6ã«ããStairPointãé
ç½®ã
ããã§é ããã®ã§
zPosã6ã«ããStairPointãé
ç½®
ãããç¹°ãè¿ãã¨ä»¥ä¸ã®ãããªé ç½®ã«ãªãã¾ãã
çµæ
ããã§ã¯ãã¬ã¤ã¤ã¼ãé段ãç»ããã®ãã確èªãã¦ã¿ã¾ãããã
ãã¬ã¤ã¤ã¼ãè£å´ã«é ãããã¨ãªãé段ãç»ããã¨ãã§ãã¾ããã
ã¾ãCustom Physics Shapeã§è¨å®ããColliderãæ©è½ãã¦ããã®ã§é段ããè½ã¡ããã¨ãããã¾ããã
ä»åã¯ä»¥ä¸ã¨ãªãã¾ãã
ãããã¨ããããã¾ãããã