private Transform groundCheck; // A position marking where to check if the player is grounded. private bool grounded = false; // Whether or not the player is grounded. private Animator anim; // Reference to the player's animator component. void Awake() { // Setting up references. // 在...
public LayerMask groundLayers; // 用于指定哪些层被视为地面的层掩码 public float rayLength = 0.1f; // 射线的长度 public Vector3 rayOriginOffset = new Vector3(0, 0.2, 0); // 从角色位置开始射线的偏移量 private bool CheckIfGrounded() // 计算射线的原点 Vector3 rayOrigin = transform.position...
在SkeletonGroundedState的Update()函数中添加 publicoverridevoidUpdate(){base.Update();if(enemy.IsPlayerDetected())stateMachine.ChangeState(enemy.battleState);} 骷髅进入战斗状态时,要随玩家位置的变化改变移动方向。因此我们引入player的位置这个变量,通过它与骷髅位置的对比确定战斗状态骷髅移动的方向。 player.posi...
LogicUpdate(); xInput = player.InputManage.NormInputX; yInput = player.InputManage.NormInputY; } public override void PhysicsUpdate() { base.PhysicsUpdate(); } } 因为玩家执行待机以及移动状态时是在地上的,所以需要继承 PlayerGroundedState 这个状态。我们可以先思考一下:在待机状态需要检测什么,以及...
目前可以看到动画控制器中,进入动画默认指向Player_idle,打开进入游戏,发现无论如何移动角色,都只执行,play_idle动画,因此,我们需要动画控制器设置不同动画之间的转换。 右键选择make Transition添加转换箭头 点击箭头可以查看转换条件 点击左侧栏Parameter添加可控制动画转换的变量: ...
[SerializeField] privatefloatgroundCheckY =0.2f;//how far down from ground chekc point is Grounded() checked[SerializeField] privatefloatgroundCheckX =0.5f;//how far horizontally from ground chekc point to the edge of the player is[SerializeField] private LayerMask whatIsGround;//sets the ground...
checkResult = Physics2D.Linecast(transform.position, groundChecks[i].position,1<< LayerMask.NameToLayer("Ground")); vida.grounded = checkResult;if(vida.grounded)break; }if(vida.grounded) {//火箭蛋(硬件蛋特殊技能)if(vida.playerType == Tags.YingjianDan) ...
//更新鼠标锁定的状态的 public void UpdateCursorLock() { //if the user set "lockCursor" we check & properly lock the cursos if (lockCursor) InternalLockUpdate(); } //控制鼠标锁定 private void InternalLockUpdate() { if (Input.GetKeyUp(KeyCode.Escape)) { m_cursorIsLocked = false; } ...
vida.grounded=checkResult; if(vida.grounded)break; if(vida.grounded) //火箭蛋(硬件蛋特殊技能) if(vida.playerType==Tags.YingjianDan) vida.jumpable=1; //按下K时 if(Input.GetKeyDown(KeyCode.K)vida.jumpTimer=0.03f) if(vida.grounded) //允许跳跃 vida.jumpTimer=0.0f; vida.jump=true; else...
一个Player脚本仍然可以管理其他的脚本组件,但每个类只做一件事。这种设计使修改代码更容易实现,特别是当项目的需求随着时间的推移而变化时。然而,另一方面,你需要在单一责任原则和合适的常识之间做好平衡。不要因为单一职责而将类细分到过于简单的极端。