Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MoveClips : MonoBehaviour
- {
- public float speed = 10f;
- Rigidbody rb;
- bool isGrounded;
- Animation P_GG;
- // Start is called before the first frame update
- void Start()
- {
- rb = GetComponent<Rigidbody>();
- P_GG = GetComponent<Animation>();
- }
- // Update is called once per frame
- void FixedUpdate()
- {
- MovementLogic();
- }
- private void MovementLogic()
- {
- float moveHorizontal = Input.GetAxis("Horizontal");
- if (Input.GetKey(KeyCode.A))
- {
- P_GG.Play("GL");
- }
- if (Input.GetKey(KeyCode.D))
- {
- P_GG.Play("GR");
- }
- float moveVertical = Input.GetAxis("Vertical");
- Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
- rb.AddForce(movement * speed);
- }
- void OnCollisionEnter(Collision collision)
- {
- IsGroundedUpate(collision, true);
- }
- void OnCollisionExit(Collision collision)
- {
- IsGroundedUpate(collision, false);
- }
- private void IsGroundedUpate(Collision collision, bool value)
- {
- if (collision.gameObject.tag == ("Ground"))
- {
- isGrounded = value;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement