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;
|
2021-07-21 09:33:24 +02:00
|
|
|
public Rigidbody2D rb;
|
|
|
|
public AudioClip RotateSFX;
|
|
|
|
|
2021-07-21 16:18:46 +02:00
|
|
|
public AudioClip damage;
|
|
|
|
public SpawnStorage spawnstor;
|
|
|
|
|
2021-07-20 18:52:15 +02:00
|
|
|
public SpriteRenderer sprite;
|
2021-07-20 18:04:44 +02:00
|
|
|
public PhysicsMaterial2D bottom;
|
2021-07-19 19:27:02 +02:00
|
|
|
public CharacterController2D controller;
|
2021-07-21 09:33:24 +02:00
|
|
|
public AudioSource sfx;
|
2021-07-19 19:27:02 +02:00
|
|
|
public float runspeed = 40f;
|
2021-07-19 21:10:31 +02:00
|
|
|
float horizonatalaxis = 0f;
|
2021-07-20 19:12:51 +02:00
|
|
|
|
2021-07-19 19:27:02 +02:00
|
|
|
bool jumping = 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-20 18:23:19 +02:00
|
|
|
if(Input.GetButtonDown("Switch")) {
|
|
|
|
switchy = !switchy;
|
2021-07-20 19:12:51 +02:00
|
|
|
if (switchy){
|
|
|
|
sprite.flipY = true;
|
2021-07-21 09:33:24 +02:00
|
|
|
rb.sharedMaterial = top;
|
2021-07-23 09:45:12 +02:00
|
|
|
controller.m_JumpVelocity = controller.m_JumpVelocity * 2f;
|
2021-07-20 19:12:51 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
sprite.flipY = false;
|
2021-07-21 09:33:24 +02:00
|
|
|
rb.sharedMaterial = bottom;
|
2021-07-23 09:45:12 +02:00
|
|
|
controller.m_JumpVelocity = controller.m_JumpVelocity / 2f;
|
2021-07-20 19:12:51 +02:00
|
|
|
}
|
2021-07-21 09:33:24 +02:00
|
|
|
sfx.clip = RotateSFX;
|
|
|
|
sfx.Play();
|
2021-07-20 18:23:19 +02:00
|
|
|
}
|
2021-07-21 16:18:46 +02:00
|
|
|
if(Input.GetButtonDown("Reset")) {
|
|
|
|
transform.position = spawnstor.spawnpoint;
|
|
|
|
transform.GetComponent<Rigidbody2D>().velocity = Vector3.zero;
|
|
|
|
sfx.clip = damage;
|
|
|
|
sfx.Play();
|
|
|
|
}
|
2021-07-21 13:45:21 +02:00
|
|
|
Vector3 playpos = transform.position;
|
|
|
|
playpos.z = 0f;
|
|
|
|
transform.position = playpos;
|
|
|
|
if (!switchy){
|
|
|
|
horizonatalaxis = Input.GetAxisRaw("Horizontal");
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
horizonatalaxis = 0;
|
|
|
|
}
|
|
|
|
jumping = Input.GetButton("Jump") || Input.GetAxisRaw("Vertical") > 0;
|
|
|
|
animator.SetFloat("Horizontal_speed", horizonatalaxis);
|
|
|
|
|
|
|
|
|
2021-07-20 18:23:19 +02:00
|
|
|
|
2021-07-20 19:12:51 +02:00
|
|
|
|
2021-07-19 11:45:08 +02:00
|
|
|
|
2021-07-19 19:27:02 +02:00
|
|
|
}
|
|
|
|
void FixedUpdate(){
|
2021-07-24 12:38:43 +02:00
|
|
|
controller.Move(horizonatalaxis * runspeed, jumping);
|
2021-07-19 19:27:02 +02:00
|
|
|
|
2021-07-19 11:45:08 +02:00
|
|
|
}
|
|
|
|
}
|