|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class PlayerControl : MonoBehaviour {
|
|
|
|
|
|
|
|
|
|
public float speed;
|
|
|
|
|
|
|
|
|
|
private Rigidbody rb;
|
|
|
|
|
|
|
|
|
|
void Start() {
|
|
|
|
|
rb = GetComponent<Rigidbody>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FixedUpdate() {
|
|
|
|
|
float moveX = Input.GetAxis("Horizontal") * speed * Time.fixedDeltaTime;
|
|
|
|
|
|
|
|
|
|
Vector3 newPosition = rb.position + new Vector3(moveX, 0, 0);
|
|
|
|
|
rb.MovePosition(newPosition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Update() {
|
|
|
|
|
if (rb.position.y < -1 && !resetting) {
|
|
|
|
|
StartCoroutine(ResetAfterTime());
|
|
|
|
|
}
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.P)) {
|
|
|
|
|
if (Time.timeScale == 1) {
|
|
|
|
|
Time.timeScale = 0;
|
|
|
|
|
} else if (Time.timeScale == 0) {
|
|
|
|
|
Time.timeScale = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool resetting = false;
|
|
|
|
|
|
|
|
|
|
private void OnCollisionEnter(Collision collision) {
|
|
|
|
|
if (collision.collider.TryGetComponent(out Wall _) && !resetting) {
|
|
|
|
|
StartCoroutine(ResetAfterTime());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerator ResetAfterTime() {
|
|
|
|
|
|
|
|
|
|
resetting = true;
|
|
|
|
|
UIControl.Instance.resetting = true;
|
|
|
|
|
UIControl.Instance.FailedMessage();
|
|
|
|
|
|
|
|
|
|
yield return new WaitForSeconds(1);
|
|
|
|
|
|
|
|
|
|
resetting = false;
|
|
|
|
|
UIControl.Instance.resetting = false;
|
|
|
|
|
|
|
|
|
|
GameObject.Find("Track").GetComponent<RunningTrack>().ResetTrack();
|
|
|
|
|
UIControl.Instance.ResetScore();
|
|
|
|
|
|
|
|
|
|
rb.position = new Vector3(0, 0.5f, 0);
|
|
|
|
|
rb.rotation = Quaternion.identity;
|
|
|
|
|
rb.velocity = Vector3.zero;
|
|
|
|
|
rb.angularVelocity = Vector3.zero;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|