]> git.lizzy.rs Git - SuperMouseAdventure.git/blob - 2DGame/Assets/Scripts/Mouse/PlayerController.cs
700dc1821244ab9640cb49011bce0c26adcaf003
[SuperMouseAdventure.git] / 2DGame / Assets / Scripts / Mouse / PlayerController.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4
5 public class PlayerController : MonoBehaviour
6 {
7     public float speed;
8     float mass;
9     Vector3 gravity;
10     public float gravityScale;
11     public float jumpForce;
12     private float moveInput;
13
14     [HideInInspector]
15     public bool isGrounded;
16     public Transform groundcheck;
17     public float checkRadius;
18     public LayerMask whatIsGround;
19
20     // Start is called before the first frame update
21     void Start()
22     {
23         gravity = new Vector3(0, gravityScale, 0);
24     }
25
26     // Update is called once per frame
27     void Update()
28     {
29         moveInput = Input.GetAxisRaw("Horizontal");
30         
31         if(Input.GetButtonDown("Jump"))
32         {
33             transform.position = new Vector3(transform.position.x, jumpForce, 0);
34         }
35     }
36
37     void FixedUpdate()
38     {
39         isGrounded = Physics2D.OverlapCircle(groundcheck.position, checkRadius, whatIsGround);
40
41         if (!isGrounded)
42         {
43             transform.position -= gravity;
44         }
45
46         transform.position += new Vector3(moveInput * speed, 0, 0);
47     }
48 }