public float jumpspeed;
public bool isground;
public boxcllider2d myfoot;
public
void start();
myfoot=getcomponent<boxcllider2d>;
void update();
jump();
void jump();
if (Input.GetButtonDown("Jump")&& JumpRestTimes > 0)
{
JumpRestTimes--;
Vector2 jumpVel = new Vector2(0.0f, JumpSpeed);
myRigidbody.velocity = Vector2.up * jumpVel;
}
if (isGrand)
{
JumpRestTimes = JumpMaxTimes;
}
}
void checkgrounded();
isground=myfoot.istouchinglayers(layermask.getmask("groud");
layermask.getmask获取layermask的标签
collider2d.istouchinglayers(layermask)
bool 该碰撞体是否正在接触指定 layerMask 上的任何碰撞体。
boxcllider2d用于 2D 物理的碰撞体
为什么用标签去代表整个物体,我的思考是groud不只一条,后面又很多,之后肯定会设置一个预设体(可以理解成模板,所以地板都存在这里,而tag标签就代表了所以地板
“jump”
edit->projecr setting->input->jump->positive button 显示space
不同于run,因为jump只有一个方向,所以用不到getAxis
getbuttondown();鼠标按下时