Create a new script, name it "SC_Weapon" and paste the code below inside it:.Select secondary weapon when pressing 1 At the start we enable the primary weapon and disable the secondary Start is called before the first frame update Public class SC_WeaponManager : MonoBehaviour Create a new script, name it "SC_WeaponManager" and paste the code below inside it:.The player weapon system will consist of 3 components: a Weapon manager, a Weapon script, and a Bullet script. Assign the Main Camera to the Player Camera variable in SC_CharacterController.Attach SC_CharacterController script to "Player" Object (You will notice that it also added another component called Character Controller, change its center value to (0, 1, 0)).Rotation.x = Mathf.Clamp(rotation.x, -lookXLimit, lookXLimit) Rotation.x += -Input.GetAxis("Mouse Y") * lookSpeed Rotation.y += Input.GetAxis("Mouse X") * lookSpeed MoveDirection.y -= gravity * ltaTime ĬharacterController.Move(moveDirection * ltaTime) This is because gravity should be applied when the moveDirection is multiplied by deltaTime). Gravity is multiplied by deltaTime twice (once here, and once below MoveDirection = (forward * curSpeedX) + (right * curSpeedY) Vector3 right = transform.TransformDirection(Vector3.right) įloat curSpeedX = canMove ? speed * Input.GetAxis("Vertical") : 0 įloat curSpeedY = canMove ? speed * Input.GetAxis("Horizontal") : 0 Vector3 forward = transform.TransformDirection(Vector3.forward) We are grounded, so recalculate move direction based on axes Public class SC_CharacterController : MonoBehaviour SC_CharacterController.cs using UnityEngine
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |