<file_sep>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnviromentMovementLoop : MonoBehaviour
{

    public Vector3 startPos;

    public Vector3 targetPos;

    private Vector3 moveTo;

    public float movementSpeed = 4;
    // Start is called before the first frame update
    void Start()
    {
       if(startPos == new Vector3(0, 0, 0))
        {
            startPos = this.transform.position;
        }
        moveTo = targetPos;
        StartCoroutine("MoveObject");

    }

    private void Update()
    {
        this.transform.position = Vector3.LerpUnclamped(transform.position, moveTo, movementSpeed * Time.deltaTime);
     
    }

    IEnumerator MoveObject()
    {
        MoveTo();

        yield return new WaitForSeconds(1);

        MoveFrom();

        yield return new WaitForSeconds(1);

        StartCoroutine("MoveObject");

    }

    private void MoveTo()
    {
        moveTo = targetPos;
    }

    private void MoveFrom()
    {
        moveTo = startPos;
    }

}
<file_sep>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Restart : MonoBehaviour
{
    public Transform startPos;
    private CharacterController cc;

    private void Start()
    {
        cc = this.GetComponent<CharacterController>();
    }

    void Update()
    {
        if (Input.GetKeyDown("r"))
            RestartPlayer();


    }

    void RestartPlayer()
    {
        cc.enabled = false;
        gameObject.transform.position = startPos.position;
        gameObject.transform.rotation = startPos.rotation;
        Debug.Log(new Vector3(startPos.position.x, startPos.position.y, startPos.position.z));
        cc.enabled = true;

        Timer.singleton.RestartTimer();
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Danger")
            RestartPlayer();
    }
}
<file_sep>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FinishTrigger : MonoBehaviour
{
    // Start is called before the first frame update
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player")
        {
            Timer.singleton.TimerFinished();
        }

    }
}
<file_sep>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Timer : MonoBehaviour
{
    public static Timer singleton;
    public float currTime = 0.0f;
    public float bestTime = 0.0f;

    public Text currTimeText;
    public Text timeToBeatText;

    public bool timerActive = false;

    private void Awake()
    {
        if (!(singleton is null) && singleton != this)
            Destroy(this);
        singleton = this;

    }

    void Update()
    {
        if(timerActive)
        RunTimer();
    }


    public void RunTimer()
    {
        currTime += Time.deltaTime;
        FormatTimer(currTime, currTimeText, "");

        if(currTime > bestTime && bestTime != 0)
        {
            currTimeText.color = new Color(1, 0, 0);  
        }

    }

    private void FormatTimer(float t, Text displayText, string info) 
    {
        string minutes = Mathf.Floor(t / 60).ToString("00");
        string seconds = Mathf.Floor(t % 60).ToString("00");
        string milis = Mathf.Floor((t * 10) % 10).ToString("0");
        displayText.text = info + string.Format("{0}:{1}.{2}", minutes, seconds, milis);
    }


    public void TimerFinished()
    {
       
        if (!timerActive)
            return;

        timerActive = false;

        if(currTime < bestTime || bestTime == 0)
        {
            bestTime = currTime;
            FormatTimer(bestTime, timeToBeatText, "Time To Beat: ");
        }


    }

    public void StartTimer()
    {
        timerActive = true;
    }

    public void RestartTimer()
    {
        currTime = 0;
        timerActive = false;
        FormatTimer(currTime, currTimeText, "");
        currTimeText.color = new Color(0, 1, 0);
    }
}
<file_sep>﻿
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;

public class MenuButton : MonoBehaviour, IPointerClickHandler
{
   

    public string _action;

    public void OnPointerClick(PointerEventData eventData)
    {
        MenuEvent(_action);
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Return))
        {
            MenuEvent(_action);
        }
    }

    private void MenuEvent(string a)
    {
       if(a == "play")
        {
            SceneManager.LoadScene("Level1");
        }
       if(a == "exit")
        {
            Application.Quit();
        }
    }
}
<file_sep>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ladder : MonoBehaviour
{

    public GameObject playerOBJ;
    public bool canClimb = false;
    float speed = 5;

    void OnCollisionEnter(Collision coll)
    {
        if (coll.gameObject.tag == "Player")
        {
            canClimb = true;
           
            playerOBJ = coll.gameObject;
            playerOBJ.GetComponent<CharacterController>().enabled = false;
        }
    }

    void OnCollisionExit(Collision coll2)
    {
        if (coll2.gameObject.tag == "Player")
        {
            canClimb = false;
            playerOBJ.GetComponent<CharacterController>().enabled = true;
            playerOBJ = null;
        }
    }
    void Update()
    {
        if (canClimb)
        {
            if (Input.GetKey(KeyCode.W))
            {
               // Debug.Log("AAAAH");
               
                playerOBJ.transform.Translate(new Vector3(0, 1, 0) * Time.deltaTime * speed);

            }
            if (Input.GetKey(KeyCode.S))
            {
                playerOBJ.transform.Translate(new Vector3(0, -1, 0) * Time.deltaTime * speed);
                if (playerOBJ.GetComponent<PlayerMovement>().isGrounded)
                {
                    canClimb = false;
                    playerOBJ.GetComponent<CharacterController>().enabled = true;
                }
            }
        }
    }
}
<file_sep>﻿using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour
{

    public CharacterController controller;

    private Camera mainCam;

    public float speed = 6f;
    public float gravityNorm = -9.81f;
    public float gravity;
    public float jumpH = 2;

    public float lockedZ;
    public float lockedX;

    public float z;
    public float x;

    public Transform groundCheck;

    public Transform wallCheckLeft;
    public Transform wallCheckRight;

    public float groundDistance = 0.4f;
    public float wallDistance = 0.3f;

    public bool isGrounded;
    public bool isWallLeft;
    public bool isWallRight;

    public bool isSliding = false;
    public bool canMove = true;

    public Vector3 velocity;
    public Vector3 movement;

    public LayerMask groundChecks;


    private void Awake()
    {
        mainCam = Camera.main;
    }

    void Update()
    {

        if (canMove)
        {

            WallRun();

            if (Input.GetKey(KeyCode.LeftShift) && !Input.GetKey("c"))
            {
                speed = 11f;
            }
            else
            {
                speed = 6f;
            }
        }
        if (isSliding)
        {
            StartCoroutine("Slide");
        }
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundChecks);
       
        if (isGrounded && velocity.y < 0)
        {
            velocity.y = -1f;
        }


        x = Input.GetAxis("Horizontal");
        z = Input.GetAxis("Vertical");
        if (canMove)
        {
            movement = transform.right * x + transform.forward * z;
        }
        else if (!canMove)
        {
            movement = transform.right * lockedX + transform.forward * lockedZ;
        }


        controller.Move(movement * speed * Time.deltaTime);

        velocity.y += gravity * Time.deltaTime;

        controller.Move(velocity * Time.deltaTime);

        if(Input.GetKeyDown("space") && isGrounded)
        {
            velocity.y = Mathf.Sqrt(jumpH * -2f * gravity);
        }
        if (Input.GetKeyDown("c") && !isSliding)
        {
            transform.localScale = new Vector3(1,0.5f,1);
            if (z > 0.5f && Input.GetKey(KeyCode.LeftShift))
            {
                isSliding = true;
            }
        }
        else if(Input.GetKeyUp("c") )
        {
            transform.localScale = new Vector3(1, 1, 1);
            isSliding = false;
            canMove = true;
        }

    }


    private void WallRun()
    {
        isWallLeft = Physics.CheckSphere(wallCheckLeft.position, wallDistance, groundChecks);
        isWallRight = Physics.CheckSphere(wallCheckRight.position, wallDistance, groundChecks);

        if ((isWallLeft || isWallRight) && velocity.y < 0)
        {
            gravity = -5f;
        }
        else
        {
            gravity = gravityNorm;
        }


    }

    IEnumerator Slide()
    {
        isSliding = false;
        LockMovement();
        speed = 15f;
        yield return new WaitForSeconds(0.4f);
        canMove = true;
        isSliding = false;
        canMove = true;
    }

    void LockMovement()
    {
        lockedZ = z;
        lockedX = x;
        canMove = false;

    }
}