图片素材的切割
1.选择需要切割的图片,点击Sprite Editor按钮

2.选择对应的切割方式,输入需要切割的尺寸,Pivot代表的是切割的中心点位置

Preset的用法
Preset为预制的设置,设置过一次后,其他需要用到相同的设置的图片就可以直接指定

点击Save按钮就可以保存当前的设置
图片渲染规则
渲染图片在图层tag和序号相同的情况下,越下方的物体层级越高
在下方的物体会遮盖上方的物体

Sorting Group用法
可以将整个子物体设置为一个图层,防止其他图层的一个渲染问题

设置整个项目按照 Y 轴渲染
设置Transparency Sort Mode以及Transparency Sort Axis

实现 Player 基本移动
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- public class Player : MonoBehaviour
- {
- //声明一个刚体组件
- private Rigidbody2D rb;
-
- //声明变量
-
- public float speed;
-
- private float inputX;
- private float inputY;
-
- private Vector2 movementInput;
-
- //Awake()在调用的时候执行
- private void Awake()
- {
- rb = GetComponent
(); - }
-
- private void Update()
- {
- PlayerInput();
- }
-
- private void FixedUpdate()
- {
- Movement();
- }
-
- ///
- /// 将用户输入的X,Y转换为坐标
- ///
- private void PlayerInput()
- {
- inputX = Input.GetAxisRaw("Horizontal");
- inputY = Input.GetAxisRaw("Vertical");
-
- //如果同时按下横向移动和纵向移动,会对速度做一个削弱
- if(inputX != 0 && inputY != 0)
- {
- inputX *= 0.6f;
- inputY *= 0.6f;
- }
-
- movementInput = new Vector2(inputX, inputY);
- }
-
- ///
- /// 让角色进行移动
- ///
- private void Movement()
- {
- rb.MovePosition(rb.position + movementInput * speed * Time.deltaTime);
- }
- }