(2)为脚本PlayerStateController中定义的动画状态枚举类型添加3种新的状态:jump、landing和falling,并且设置当玩家按下键盘上的空格键时,精灵会进入跳跃状态。脚本PlayerStateController中的部分代码如下: 01 using UnityEngine; 02 using System.Collections; 03 04 public class PlayerStateController : MonoBehaviour 05 ...
3、PLAYER设置完成后保存为Prefab 四、随机生成平台 在屏幕下方某处生成平台,同时作为角色死亡的判定位置。 创建Empty,reset并调整位置,添加BoxCollider2D,勾选isTrigger,调整box形状,将tag设置为Spikes,如图所示 创建随机生成平台脚本:用一个List来保存所有要生成的平台类型,设置生成平台的时间间隔spawnTime,以及生成平台...
if (Input.GetAxisRaw("Vertical") == -1 && Input.GetButtonDown("Jump")) { isJumpDown = true; } } void FixedUpdate() { isGrounded = Physics2D.OverlapCircle(transform.position, groundCheckRadius, groundLayer); if (isGrounded) { isJumping = false; isFalling = false; } if (rb.velocity.y...
anim.SetBool("falling", false); //从下落回到站立 } else if(rb.velocity.y > 0) //向上移动 { anim.SetBool("jumping", true); anim.SetBool("falling", false); } else if(rb.velocity.y < 0) //掉落 { anim.SetBool("jumping", false); anim.SetBool("falling", true); } if(isHurt) ...
if (collider.gameObject.tag == "Player") { GameController.Score++; // Create particle system at the game objects position // with no rotation. Instantiate(_smokeEffect, transform.position, Quaternion.identity); // Don’t do: Destroy(this) because "this" // is a script component on a ...
}// Update is called once per framevoidUpdate(){ MoveMent(); }voidMoveMent(){ isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);//检测是否在地面if(isGrounded && velocity.y <0) {//防止在真正掉落到地面前 停止掉落velocity.y =-2; ...
“下跳问题”的根本不是不能if (按下下跳) {角色往下跳},而是下跳的过程在逻辑中与自然下落是冲突...
Now, when you click on the player, movement script, there will be options for you to tinker with. Finally for jumping you need to: Set ground layer to ground objects that can be jumped on Make a isGrounded empty object to be placed at the feet of the player to check if there is *...
If I walk down stairs or angled platforms, the player is keep falling rapidly, what stops the player from being able to jump. Is there an easy way to prevent this? edit: Found some solutions here -> http://answers.unity3d.com/questions/33 ... -walk.html ...
We also need to check if our character is grounded to make a jump. We will apply vertical force to a rigidbody by using the AddForce function that takes the vector as a parameter and pushes a rigidbody in the specified direction. We will also toggle Jumping boolean to true, as we ...