SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class PlayerController : MonoBehaviour
  7. {
  8.     public float movementSpeed;
  9.     public float jumpForce;
  10.     public float checkRadius;
  11.     public int directionInput;
  12.     public LayerMask whatIsGround;
  13.     public LayerMask whatIsBox;
  14.     public Transform check;
  15.     public Transform checkHorizontal;
  16.  
  17.     public Button dialogButton;
  18.     public Button trueButton;
  19.     public Button falseButton;
  20.  
  21.     public GameObject panel;
  22.  
  23.     private bool facingRight;
  24.     private bool isGrounded;
  25.     private bool isBox;
  26.     private Rigidbody2D rb;
  27.  
  28.     private void Start()
  29.     {
  30.         rb = GetComponent<Rigidbody2D>();
  31.         facingRight = true;
  32.         dialogButton.enabled = false;
  33.     }
  34.     private void FixedUpdate()
  35.     {
  36.         isBox = Physics2D.OverlapCircle(checkHorizontal.position, checkRadius, whatIsBox);
  37.         if(isBox == true)
  38.         {
  39.             dialogButton.gameObject.SetActive(true);
  40.             dialogButton.enabled = true;
  41.            
  42.         }
  43.  
  44.         rb.velocity = new Vector2(movementSpeed * directionInput, rb.velocity.y);
  45.         isGrounded = Physics2D.OverlapCircle(check.position, checkRadius, whatIsGround);
  46.  
  47.         if ((directionInput > 0) && (facingRight == false))
  48.         {
  49.             Flip();
  50.         }
  51.         else if ((directionInput < 0) && (facingRight == true))
  52.         {
  53.             Flip();
  54.         }
  55.         if (panel.activeSelf == true)
  56.         {
  57.             rb.constraints = RigidbodyConstraints2D.FreezePositionX;
  58.  
  59.  //           Destroy(GameObject.FindGameObjectWithTag("box"));
  60.  
  61.             dialogButton.gameObject.SetActive(false);
  62.             dialogButton.enabled = false;
  63.  
  64.             trueButton.gameObject.SetActive(true);
  65.             trueButton.enabled = true;
  66.  
  67.             falseButton.gameObject.SetActive(true);
  68.             trueButton.enabled = true;
  69.  
  70.         }
  71.     }
  72.     private void Flip()
  73.     {
  74.         facingRight = !facingRight;
  75.         Vector3 Scaler = transform.localScale;
  76.         Scaler.x *= -1;
  77.         transform.localScale = Scaler;
  78.     }
  79.     public void Move(int InputAxes)
  80.     {
  81.         directionInput = InputAxes;
  82.     }
  83.     public void Jump(bool isJump)
  84.     {
  85.         if(isGrounded == true)
  86.         {
  87.             rb.velocity = new Vector2(rb.velocity.y, jumpForce);
  88.         }
  89.     }
  90.  /*   void OnCollisionStay2D (Collision2D col)
  91.     {
  92.         if(col.gameObject.tag == "box")
  93.         {
  94.             dialogButton.gameObject.SetActive(true);
  95.             dialogButton.enabled = true;
  96.         }
  97.         else
  98.         {
  99.             dialogButton.gameObject.SetActive(false);
  100.             dialogButton.enabled = false;
  101.         }
  102.     }*/
  103.     public void TrueButton()
  104.     {
  105.         GameObject panel = GameObject.FindGameObjectWithTag("panelDialog");
  106.         panel.gameObject.SetActive(false);
  107.         trueButton.gameObject.SetActive(false);
  108.         trueButton.enabled = false;
  109.         falseButton.gameObject.SetActive(false);
  110.         falseButton.enabled = false;
  111.         rb.constraints = RigidbodyConstraints2D.None;
  112.     }
  113. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top