Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Pause.CS
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Pause : MonoBehaviour
- {
- public GameObject pausePanel;
- public PlayerController controller;
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Escape))
- {
- pausePanel.SetActive(!pausePanel.activeSelf);
- controller.isActive = !pausePanel.activeSelf;
- if (pausePanel.activeSelf)
- Time.timeScale = 0;
- else
- Time.timeScale = 1;
- // Time.timeScale = pausePanel.activeSelf ? 0 : 1;
- }
- }
- public void Unpause()
- {
- pausePanel.SetActive(!pausePanel.activeSelf);
- controller.isActive = !pausePanel.activeSelf;
- Time.timeScale = 1;
- }
- public void QuitGame()
- {
- Application.Quit();
- }
- }
- StartMenu.cs
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class StartMenu : MonoBehaviour
- {
- public PlayerController controller;
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- }
- public void StartGame()
- {
- Debug.Log("test");
- SceneManager.LoadScene("Gam120Project1");
- }
- public void QuitGame()
- {
- Application.Quit();
- }
- }
- PlayerController.cs
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerController : MonoBehaviour
- {
- public float horizontal = 0;
- public float vertical = 0;
- private Rigidbody2D rb;
- [SerializeField]private SpriteRenderer sr;
- public float moveSpeed = 5;
- private Animator anim;
- private float jumpforce = 8;
- private bool isjumping = false;
- private bool isgrounded = true;
- public bool isActive = true;
- // Start is called before the first frame update
- void Start()
- {
- rb = GetComponent<Rigidbody2D>();
- anim = GetComponent<Animator>();
- }
- // Update is called once per frame
- void Update()
- {
- if (isActive)
- {
- horizontal = Input.GetAxisRaw("Horizontal");
- isjumping = Input.GetKeyDown(KeyCode.Space);
- anim.SetBool("IsMoving", horizontal != 0 || vertical != 0);
- if (horizontal < 0 && sr.flipX == false)
- sr.flipX = true;
- else if (horizontal > 0 && sr.flipX == true)
- sr.flipX = false;
- }
- }
- void FixedUpdate()
- {
- print (isgrounded);
- Vector2 NewMovement = new Vector2(horizontal, 0).normalized * moveSpeed;
- if (isjumping && isgrounded) NewMovement += new Vector2(0, jumpforce);
- else NewMovement += new Vector2(0, rb.velocity.y);
- rb.velocity = NewMovement;
- }
- private void OnCollisionEnter2D(Collision2D collision)
- {
- isgrounded = true;
- }
- private void OnCollisionExit2D(Collision2D collision)
- {
- isgrounded = false;
- }
- private void OnCollisionStay2D(Collision2D collision)
- {
- isgrounded = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement