学习内容来自 B站up : M_Studio
文中使用图片素材来自unity素材库 2D- Sunnyland
简单角色移动完整代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControl : MonoBehaviour
{
public Rigidbody2D rb;
public Animator Anim;
public Collider2D coll;
public float speed;
public float jumphigh;
public LayerMask Ground;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
Playermove();
SwitchAnim();
}
void Playermove()
{
float Horizontalmove;
float Facedirection;
Horizontalmove = Input.GetAxis("Horizontal");
Facedirection = Input.GetAxisRaw("Horizontal");
// 移动
if (Facedirection != 0)
{
transform.localScale = new Vector3(Facedirection, 1, 1);
}
if (Horizontalmove