6월, 2019의 게시물 표시

How to create tilemap in Unity2D

이미지
1. Select GameObject > 2D Object > Tilemap in unity menu. 2. GameObject "Grid" and "Tilemap" will be created as below 3. Select Window > 2D > Tile Palette in menu 4. Select "Create New Select" as below screen shot and then create new palette 5. Select folder to store palette file 6. Register tile image as below 7. In Tile Palette window, select tile brush and "Paint a filled box with active brush" tool (center icon) in tool bar 8. Go to the Scene window. You can see grid as below 9. Drag tile on the grid of Scene window to create tile map

Move character

1. Move 2D sprite image using virtual joystick in Unity. 2. I used CrossPlatformInputManager of Unity Standard Asset for joystick script. using System . Collections ; using System . Collections . Generic ; using UnityEngine ; using UnityStandardAssets . CrossPlatformInput ; public class PlayerScript : MonoBehaviour { public static PlayerScript instance ; public float speed ; void Start ( ) { instance = this ; } // Update is called once per frame void Update ( ) { float axisX = CrossPlatformInputManager . GetAxis ( "Horizontal" ) ; float axisY = CrossPlatformInputManager . GetAxis ( "Vertical" ) ; Vector3 moveVec = new Vector3 ( axisX , axisY , 0 ) ; float rot = Mathf . Atan2 ( axisX , axisY ) * Mathf . Rad2Deg ; transform . rotation = Quaternion . Euler ( new Vector3 ( 0 , 0 , - rot ) ) ; this . transform . Translate ( moveVec * speed * Time . de