Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class PlayerController : MonoBehaviour
- {
- public float movementSpeed;
- public float jumpForce;
- public float checkRadius;
- public int directionInput;
- public LayerMask whatIsGround;
- public LayerMask whatIsBox;
- public Transform check;
- public Transform checkHorizontal;
- public Button dialogButton;
- public Button trueButton;
- public Button falseButton;
- public GameObject panel;
- private bool facingRight;
- private bool isGrounded;
- private bool isBox;
- private Rigidbody2D rb;
- private void Start()
- {
- rb = GetComponent<Rigidbody2D>();
- facingRight = true;
- dialogButton.enabled = false;
- }
- private void FixedUpdate()
- {
- isBox = Physics2D.OverlapCircle(checkHorizontal.position, checkRadius, whatIsBox);
- if(isBox == true)
- {
- dialogButton.gameObject.SetActive(true);
- dialogButton.enabled = true;
- }
- rb.velocity = new Vector2(movementSpeed * directionInput, rb.velocity.y);
- isGrounded = Physics2D.OverlapCircle(check.position, checkRadius, whatIsGround);
- if ((directionInput > 0) && (facingRight == false))
- {
- Flip();
- }
- else if ((directionInput < 0) && (facingRight == true))
- {
- Flip();
- }
- if (panel.activeSelf == true)
- {
- rb.constraints = RigidbodyConstraints2D.FreezePositionX;
- // Destroy(GameObject.FindGameObjectWithTag("box"));
- dialogButton.gameObject.SetActive(false);
- dialogButton.enabled = false;
- trueButton.gameObject.SetActive(true);
- trueButton.enabled = true;
- falseButton.gameObject.SetActive(true);
- trueButton.enabled = true;
- }
- }
- private void Flip()
- {
- facingRight = !facingRight;
- Vector3 Scaler = transform.localScale;
- Scaler.x *= -1;
- transform.localScale = Scaler;
- }
- public void Move(int InputAxes)
- {
- directionInput = InputAxes;
- }
- public void Jump(bool isJump)
- {
- if(isGrounded == true)
- {
- rb.velocity = new Vector2(rb.velocity.y, jumpForce);
- }
- }
- /* void OnCollisionStay2D (Collision2D col)
- {
- if(col.gameObject.tag == "box")
- {
- dialogButton.gameObject.SetActive(true);
- dialogButton.enabled = true;
- }
- else
- {
- dialogButton.gameObject.SetActive(false);
- dialogButton.enabled = false;
- }
- }*/
- public void TrueButton()
- {
- GameObject panel = GameObject.FindGameObjectWithTag("panelDialog");
- panel.gameObject.SetActive(false);
- trueButton.gameObject.SetActive(false);
- trueButton.enabled = false;
- falseButton.gameObject.SetActive(false);
- falseButton.enabled = false;
- rb.constraints = RigidbodyConstraints2D.None;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement