2
我有一段代码试图让玩家只通过点击在2个盒子之间跳跃立方体1(位于左侧)和立方体2(在右侧)。团结:玩家跳跃问题
Move()函数的问题在于它开始从多维数据集1跳到多维数据集2,然后多维数据集2再次跳转到多维数据集1,但是从这一点开始,玩家从多维数据集1跳到左边的对面立方体2.
跳转功能正在工作,但我认为逻辑错误。
移动:
void Move(){
int i = 0;
while ((isGrounded == true) && (i < 10)) {
if(atCube1 == true){
JumpRight();
}
if(atCube2 == true){
JumpLeft();
}
i++;
}
}
OnCollisionEnter:
void OnCollisionEnter (Collision col)
{
Debug.Log("OnCollisionEnter");
if (col.gameObject.name == "Cube 1"){
Debug.Log ("++++++ C U B E 1 H I T ++++++++");
atCube1 = true;
isGrounded = true;
}
if(col.gameObject.name == "Cube 2"){
Debug.Log ("Cube 2 hit");
atCube2 = true;
isGrounded = true;
}
}
我修复了您的格式。两件事:1)你不需要'==真'。 2)如果'atCube1'和'atCube2'都是真的? –
您的JumpRight功能是否重置atCube1和isGrounded字段值? –
嗨@Wai,感谢您回应,我不认为atCube1和2可以在同一时间正确,因为这是在OnCollisionEnter功能,请参见下面的它,\t无效OnCollisionEnter(冲突COL) \t { \t \t调试.LOG( “OnCollisionEnter”); \t \t \t 如果\t(col.gameObject.name == “立方1”){ \t \t \t的debug.log( “++++++ CUBE 1个HIT ++++++++”) ; \t \t \t atCube1 = true; \t \t \t isGrounded = true; \t \t \t } \t \t \t如果(col.gameObject.name == “立方2”){ \t \t \t调试。日志(“Cube 2 hit”); \t \t \t atCube2 = true; \t \t \t isGrounded = true; \t \t \t \t \t}} – tony2016