目录
一、游戏素材获取itch.io
unity游戏人物素材可以到itch.io网站上寻找
可以避免很多像人物角色背景不透明问题,因为itch.io上的素材包背景大多已经处理好了
可以省去很多功夫。
二、图片分割(切片)
可以通过切片做出动画效果
推荐自动分割:
1、按照行列(推荐)
2、按照大小
无法自动分割的时候手动切片
三、实现人物移动
3.1设置碰撞边界
组件:Box Collider 2D或者Circle Collider 2D
3.2设置刚体
组件:Rigidbody
3.3编写脚本
组件:new script
using System.Collections;
using System.Collections.Generic;
using UnityEditor.Tilemaps;
using UnityEngine;
public class move : MonoBehaviour
{
// Start is called before the first frame update
public float speed;
Rigidbody2D rb;
bool facingRight = true;
void filp() {
transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
facingRight = !facingRight;
}
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
float input = Input.GetAxisRaw("Horizontal");
if (input > 0 && facingRight == false)
{
filp();
}
else if (input < 0 && facingRight == true)
{
filp();
}
rb.velocity = new Vector2(input * speed, rb.velocity.y);
}
}