本篇代码主要实现是角色的行走和跳跃
1//角色刚体点开模拟,不然没法起跳,怕下坠可以在下面放一个固定的刚体作为地板。
2//所需要用到的组件
3//代码和注释
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pleyar : MonoBehaviour //前提:为当前的角色创建子物体作为跳跃检测工具
{
public float MoveSpeed = 0.1f; //水平位移量
public float jumpSpeed =4f; //跳跃位移量
private Rigidbody2D player; //当前人物刚体名称
private bool grounded = false; //角色是否在地面
private Transform GameObject; //跳跃检测工具 :若向二段跳就增加GameOject与角色的Y轴距离 this.GetComponent<Transform>().position = new Vector3(0,flat_Y); || Transform.position.x
// bool facingRight = false; //角色是否面向右边
private void Start()
{
player = transform.GetComponent<Rigidbody2D>();//人物的刚体位置数据
}
private void Awake()
{
GameOb