using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelMenu : MonoBehaviour
{
public static bool pausedGame;
public Canvas pauseMenuUI;
public AudioSource music;
void Start ()
{
pausedGame = false;
}
void Update ()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
DecisionPause();
}
}
public void Resume()
{
pauseMenuUI.enabled = false;
Time.timeScale = 1f;
pausedGame = false;
music.UnPause();
}
public void Pause()
{
pauseMenuUI.enabled = true;
Time.timeScale = 0f;
pausedGame = true;
music.Pause();
}
private void DecisionPause()
{
if (pausedGame)
{
Resume();
}
else
{
Pause();
}
}
public void ReturnToMenu()
{
Time.timeScale = 1f;
SceneManager.LoadScene(0);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public Rigidbody2D myRigidbody;
public Animator myAnimator;
[SerializeField]
private LayerMask whatIsGround;
[SerializeField]
private Transform[] groundPoints;
[SerializeField]
private float movementSpeed = 8f, jumpForce = 300f, groundRadius = 0.5f;
private bool slide;
private bool lookRight;
private bool groundTouch, jump;
public bool iHasKey;
public bool enterDoor;
void Start ()
{
iHasKey = false;
enterDoor = false;
lookRight = true;
myRigidbody = GetComponent();
myAnimator = GetComponent();
}
void Update ()
{
InputControl();
}
private void FixedUpdate()
{
float horizontal = Input.GetAxis("Horizontal");
groundTouch = IsGrounded();
MovementControl(horizontal);
LookDirection(horizontal);
LayerControl();
ResetValues();
}
private void InputControl()
{
if (Input.GetKeyDown(KeyCode.Space))
{
jump = true;
}
if (Input.GetKeyDown(KeyCode.LeftShift))
{
slide = true;
}
if (Input.GetKeyDown(KeyCode.E))
{
enterDoor = true;
Invoke("StopEnteringDoor", 0.3f);
}
}
private void MovementControl(float horizontal)
{
if (myRigidbody.velocity.y < 0) { myAnimator.SetBool("falling", true); } Vector2 movement = new Vector2(horizontal * movementSpeed, myRigidbody.velocity.y); myRigidbody.velocity = movement; if (groundTouch && jump) //Jump { myRigidbody.AddForce(new Vector2(0, jumpForce)); myAnimator.SetTrigger("jump"); } if (slide && !this.myAnimator.GetCurrentAnimatorStateInfo(0).IsName("Slide")) //Slide { myAnimator.SetBool("slide", true); } else //Not Slide { myAnimator.SetBool("slide", false); } myAnimator.SetFloat("speed", Mathf.Abs(horizontal)); } private void LookDirection(float horizontal) { if (horizontal > 0 && !lookRight || horizontal < 0 && lookRight)
{
lookRight = !lookRight;
Vector2 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
private bool IsGrounded()
{
if (myRigidbody.velocity.y <= 0)
{
foreach (Transform point in groundPoints)
{
Collider2D[] colliders = Physics2D.OverlapCircleAll(point.position, groundRadius, whatIsGround);
for (int i = 0; i < colliders.Length; i++)
{
if (colliders[i].gameObject != this.gameObject)
{
myAnimator.ResetTrigger("jump");
myAnimator.SetBool("falling", false);
return true;
}
}
}
}
return false;
}
private void ResetValues()
{
slide = false;
groundTouch = false;
jump = false;
}
private void StopEnteringDoor()
{
enterDoor = false;
}
private void LayerControl()
{
if (!groundTouch)
{
myAnimator.SetLayerWeight(1, 1);
}
else
{
myAnimator.SetLayerWeight(1, 0);
}
}
private void OnTriggerStay2D(Collider2D collision)
{
if (!collision)
{
enterDoor = false;
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Key")
{
iHasKey = true;
}
}
}
.using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyMovement : MonoBehaviour
{
[SerializeField]
private bool moveRight;
[SerializeField]
private float speed = 1;
private Rigidbody2D myRigidbody;
void Start()
{
myRigidbody = GetComponent();
moveRight = true;
}
void FixedUpdate()
{
if (moveRight)
{
Vector2 movement = new Vector2(speed, myRigidbody.velocity.y);
myRigidbody.velocity = movement;
}
else
{
Vector2 movement = new Vector2(-speed, myRigidbody.velocity.y);
myRigidbody.velocity = movement;
}
}
private void LookDirecion()
{
Vector2 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
private void OnTriggerEnter2D(Collider2D collision)
{
Debug.Log("Penis");
if (collision.tag == "EnemyTrigger")
{
moveRight = !moveRight;
LookDirecion();
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class KillPlayer : MonoBehaviour
{
private Scene currentScene;
private void Start()
{
currentScene = SceneManager.GetActiveScene();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Player")
{
SceneManager.LoadScene(currentScene.buildIndex);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraScript : MonoBehaviour
{
[SerializeField]
private float xMax, yMax;
[SerializeField]
private float xMin, yMin;
private Transform playerMovement;
[SerializeField]
private GameObject playerToFollow;
void Start ()
{
playerMovement = playerToFollow.transform;
}
void Update ()
{
transform.position = new Vector3(Mathf.Clamp(playerMovement.position.x, xMin, xMax), Mathf.Clamp(playerMovement.position.y, yMin, yMax), transform.position.z);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class KeyScript : MonoBehaviour
{
[SerializeField]
private Image keyToChest;
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Player")
{
keyToChest.enabled = true;
DestroyMyself();
}
}
private void DestroyMyself()
{
Destroy(gameObject);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class TreasureChest : MonoBehaviour
{
[SerializeField]
private Animator myAnimator;
[SerializeField]
GameObject winTextUi;
private bool playerGotTheKey;
private int scene;
void Start ()
{
winTextUi.SetActive(false);
playerGotTheKey = false;
scene = SceneManager.GetActiveScene().buildIndex;
}
void Update ()
{
if (playerGotTheKey)
{
myAnimator.SetBool("keyIsCollected", true);
winTextUi.SetActive(true);
PlayerPrefs.SetInt("WichLevel", scene);
Invoke("ExitToMenu", 2f);
}
}
private void ExitToMenu()
{
SceneManager.LoadScene(0);
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Player")
{
playerGotTheKey = collision.gameObject.GetComponent().iHasKey;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WinninGame : MonoBehaviour
{
public bool level1;
public bool level2;
[SerializeField]
private int wichLevelIsTrue;
[SerializeField]
GameObject winTextUi;
private void Start ()
{
winTextUi.SetActive(false);
wichLevelIsTrue += PlayerPrefs.GetInt("WichLevel");
}
private void Update()
{
if (wichLevelIsTrue == 0)
{
level1 = true;
level2 = false;
}
else if (wichLevelIsTrue == 1)
{
level1 = false;
level2 = true;
}
else if (wichLevelIsTrue == 2)
{
winTextUi.SetActive(true);
if (Input.GetKeyDown(KeyCode.Escape))
{
PlayerPrefs.SetInt("WichLevel", 0);
Application.Quit();
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GateExit : MonoBehaviour
{
private bool enter;
private bool playerIsHere;
private void Start()
{
playerIsHere = false;
enter = false;
}
private void Update()
{
if (playerIsHere)
{
transform.GetChild(2).gameObject.SetActive(true);
}
else
{
transform.GetChild(2).gameObject.SetActive(false);
}
if (enter)
{
EnterGate();
}
}
private void OnTriggerStay2D(Collider2D collision)
{
if (collision.tag == "Player")
{
playerIsHere = true;
enter = collision.gameObject.GetComponent().enterDoor;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
playerIsHere = false;
}
private void EnterGate()
{
PlayerPrefs.SetInt("WichLevel", 0);
Application.Quit();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GateLvl1 : MonoBehaviour
{
private GameObject winningCounter;
private bool canIEnter;
private bool playerIsHere;
private bool enter;
private void Start()
{
winningCounter = GameObject.Find("WinningGame");
enter = false;
playerIsHere = false;
}
private void Update()
{
canIEnter = winningCounter.GetComponent().level1;
if (playerIsHere)
{
transform.GetChild(2).gameObject.SetActive(true);
}
else
{
transform.GetChild(2).gameObject.SetActive(false);
}
if (enter && canIEnter)
{
EnterGate();
}
}
private void OnTriggerStay2D(Collider2D collision)
{
if (collision.tag == "Player")
{
playerIsHere = true;
enter = collision.gameObject.GetComponent().enterDoor;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
playerIsHere = false;
}
private void EnterGate()
{
SceneManager.LoadScene(1);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GateLvl2 : MonoBehaviour
{
private GameObject winningCounter;
private bool canIEnter;
private bool enter;
private bool playerIsHere;
private void Start()
{
winningCounter = GameObject.Find("WinningGame");
enter = false;
playerIsHere = false;
}
private void Update()
{
canIEnter = winningCounter.GetComponent().level2;
if (playerIsHere)
{
transform.GetChild(2).gameObject.SetActive(true);
}
else
{
transform.GetChild(2).gameObject.SetActive(false);
}
if (enter && canIEnter)
{
EnterGate();
}
}
private void OnTriggerStay2D(Collider2D collision)
{
if (collision.tag == "Player")
{
playerIsHere = true;
enter = collision.gameObject.GetComponent().enterDoor;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
playerIsHere = false;
}
private void EnterGate()
{
SceneManager.LoadScene(2);
}
}