然后为Bullet添加Rigidbody 2D(刚体)、Box Collider 2D(碰撞器)、Script(脚本)。其中Rigidbody 2D(刚体)注意Gravity Scale(重力)设置为0,这样可以直线发射子弹,然后勾选掉Freeze Rotation(自由旋转)。Box Collider 2D(碰撞器)里面要勾选is Trigger(扳机),后面代码要用到OnTriggerEnter2D(和OnCollisionEnter2D的区别在...
// In the AIPath.cs script, find the line that looks like// movementPlane = graph != null ? graph.transform : GraphTransform.identityTransform;// and replace it withvargraphRotation=newVector3(-90,0,0);movementPlane=newGraphTransform(Matrix4x4.TRS(Vector3.zero,Quaternion.Euler(graphRotation...
//玩家往上的时候速度为正故 movement.verticalSpeed肯定大于-movement.maxFallSpeed,当玩家掉下的时候速度为负数,故可以和-movement.maxFallSpeed比较大小 movement.verticalSpeed = Mathf.Max (movement.verticalSpeed, -movement.maxFallSpeed); } function CalculateJumpVerticalSpeed (targetJumpHeight : float) {//...
publicclassCharacterController2D:MonoBehaviour { [SerializeField] privatefloatm_JumpForce =400f;// Amount of force added when the player jumps.[Range(0,1)] [SerializeField] privatefloatm_CrouchSpeed =.36f;// Amount of maxSpeed applied to crouching movement. 1 = 100%[Range(0,.3f)] [SerializeF...
}privatevoidMidAirMovement(){if(isJumpPressed) { isJumpPressed =false; player_Rbody.AddForce(newVector2(0, jumpForce), ForceMode2D.Impulse);//对角色刚体添加纵向的力} } } 3.拖拽PlayerControl脚本挂载到Player下(Inspector窗口中) 运行游戏后,按A键D键和Space键,就能分别控制角色左右移动和跳跃了。
Player Movement和Bullet Destroy小节则分别教你如何实现玩家移动和子弹销毁的功能,这是游戏交互的基础。Bullet Sound和Player Health Script等小节则进一步丰富了游戏的功能和玩法,包括添加声音效果、玩家生命值系统等。Player Healthbar和Player Healthbar Script则教你如何为玩家添加生命值条,提升游戏的可玩性和挑战性...
//Fetch the Rigidbody from the GameObject with this script attached m_Rigidbody = GetComponent<Rigidbody>(); } void FixedUpdate() { //Store user input as a movement vector Vector3 m_Input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); ...
这里的方法是,先确定角色的位置,和将要到达的位置,然后在通过Rigidbody2D.MovePosition方法移动。 先提炼下代码。 publicclassCharacterController2D:MonoBehaviour{Rigidbody2Dm_Rigidbody2D;Vector2m_PreviousPosition;Vector2m_CurrentPosition;Vector2m_NextMovement;voidAwake(){m_Rigidbody2D=GetComponent'<'Rigidbody2D'...
这里的方法是,先确定角色的位置,和将要到达的位置,然后在通过Rigidbody2D.MovePosition方法移动。 先提炼下代码。 publicclassCharacterController2D:MonoBehaviour{Rigidbody2Dm_Rigidbody2D;Vector2m_PreviousPosition;Vector2m_CurrentPosition;Vector2m_NextMovement;voidAwake(){m_Rigidbody2D=GetComponent'<'Rigidbody2D'...
Unity 2D Touch Movement 操作步骤 1、下载素材http://pan.bai /s/1gdkQz8v 2、新建三个GUITexture(Joystick)及一个Sprite(Nyan) 场景搭建 3、创建背景及Platform(添加BoxCollider2D) TouchControls.cs 4、创建脚本 TouchControls.cs usingUnityEngine;usingSystem.Collections;publicclassTouchControls:MonoBehaviour{...