GeoJam2021/Assets/Scripts/PlayerControls.cs
2021-07-21 09:54:17 +02:00

63 lines
1.6 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControls : MonoBehaviour
{
public Animator animator;
public PhysicsMaterial2D top;
public Rigidbody2D rb;
public AudioClip RotateSFX;
public SpriteRenderer sprite;
public PhysicsMaterial2D bottom;
public CharacterController2D controller;
public RigidbodyConstraints2D topx;
public RigidbodyConstraints2D bottomx;
public AudioSource sfx;
public float runspeed = 40f;
float horizonatalaxis = 0f;
bool jumping = false;
bool switchy = false;
void Start()
{
}
// Update is called once per frame
void Update()
{
horizonatalaxis = Input.GetAxisRaw("Horizontal");
jumping = Input.GetButton("Jump") || Input.GetAxisRaw("Vertical") > 0;
animator.SetFloat("Horizontal_speed", horizonatalaxis);
if(Input.GetButtonDown("Switch")) {
switchy = !switchy;
if (switchy){
sprite.flipY = true;
rb.constraints = topx;
rb.sharedMaterial = top;
controller.m_JumpForce = controller.m_JumpForce * 1.2f;
}
else {
sprite.flipY = false;
rb.constraints = bottomx;
rb.sharedMaterial = bottom;
controller.m_JumpForce = controller.m_JumpForce * 0.8f;
}
sfx.clip = RotateSFX;
sfx.Play();
}
}
void FixedUpdate(){
controller.Move(horizonatalaxis * runspeed * Time.fixedDeltaTime, jumping);
}
}