2021-07-19 11:45:08 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class PlayerControls : MonoBehaviour
|
|
|
|
{
|
2021-07-19 21:10:31 +02:00
|
|
|
public Animator animator;
|
2021-07-20 18:04:44 +02:00
|
|
|
public PhysicsMaterial2D top;
|
|
|
|
public Rigidbody2D rigidbody;
|
|
|
|
public PhysicsMaterial2D bottom;
|
2021-07-19 19:27:02 +02:00
|
|
|
public CharacterController2D controller;
|
|
|
|
public float runspeed = 40f;
|
2021-07-19 21:10:31 +02:00
|
|
|
float horizonatalaxis = 0f;
|
2021-07-19 19:27:02 +02:00
|
|
|
bool jumping = false;
|
|
|
|
bool crouching = false;
|
2021-07-20 18:04:44 +02:00
|
|
|
bool switchy = false;
|
|
|
|
|
2021-07-19 11:45:08 +02:00
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
2021-07-19 21:10:31 +02:00
|
|
|
|
|
|
|
horizonatalaxis = Input.GetAxisRaw("Horizontal");
|
2021-07-19 19:27:02 +02:00
|
|
|
jumping = Input.GetButton("Jump") || Input.GetAxisRaw("Vertical") > 0;
|
|
|
|
crouching = Input.GetButton("Crouch") || Input.GetAxisRaw("Vertical") < 0;
|
2021-07-19 21:10:31 +02:00
|
|
|
animator.SetFloat("Horizontal_speed", horizonatalaxis);
|
2021-07-20 18:04:44 +02:00
|
|
|
switchy = Input.GetButton("Switch");
|
|
|
|
if (switchy){
|
|
|
|
transform.rotation = new Quaternion(0f, 0f, 180f, 0f);
|
|
|
|
rigidbody.sharedMaterial = top;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
transform.rotation = new Quaternion(0f, 0f, 0f, 0f);
|
|
|
|
rigidbody.sharedMaterial = bottom;
|
|
|
|
}
|
2021-07-19 11:45:08 +02:00
|
|
|
|
2021-07-19 19:27:02 +02:00
|
|
|
}
|
|
|
|
|
2021-07-19 21:10:31 +02:00
|
|
|
public void crouchingx(bool stat){
|
2021-07-20 18:04:44 +02:00
|
|
|
//animator.SetBool("Crouching", stat);
|
2021-07-19 21:10:31 +02:00
|
|
|
}
|
2021-07-19 19:27:02 +02:00
|
|
|
void FixedUpdate(){
|
2021-07-20 18:04:44 +02:00
|
|
|
controller.Move(horizonatalaxis * runspeed * Time.fixedDeltaTime, false, jumping);
|
2021-07-19 19:27:02 +02:00
|
|
|
|
2021-07-19 11:45:08 +02:00
|
|
|
}
|
|
|
|
}
|