【发布时间】:2021-04-13 15:40:43
【问题描述】:
这是我在 void Update 中更新的跳转代码
void Jump()
{
if(isgrounded == true)
{
amountofjumps = jumps;
}
if(Input.GetKeyDown(KeyCode.UpArrow) && amountofjumps > 0)
{
rb2d.velocity = Vector2.up * jump * Time.deltaTime;
amountofjumps--;
}
else if(Input.GetKeyDown(KeyCode.UpArrow) && amountofjumps == 0 && isgrounded == true)
{
rb2d.velocity = Vector2.up * jump * Time.deltaTime;
}
}
这是我用于跳转代码的变量
bool isgrounded;
public float groundcheckradius;
public LayerMask whatisground;
public float jump;
private int amountofjumps;
public int jumps;
这是我检测地面的方法
void checkforground()
{
isgrounded = Physics2D.Raycast(transform.position,Vector2.down, groundcheckradius,whatisground);
}
void OnDrawGizmos()
{
Gizmos.color = Color.red;
Gizmos.DrawLine(transform.position, transform.position + Vector3.down * groundcheckradius);
}
提前致谢
【问题讨论】:
-
你的变量的初始值是多少?
-
初始值是什么意思?
-
变量将被设置为的第一个值
-
bool isgrounded = false groundcheckradius = 0.6 float jump = 67 int jumps = 1
标签: unity3d