SHARE
TWEET

Tacos Controller

a guest Nov 12th, 2019 66 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.SceneManagement;
  5. using UnityEngine.UI;
  6.  
  7. public class controller : MonoBehaviour
  8. {
  9.     public float speed;
  10.     public float jump;
  11.     public GameObject rayOrigin;
  12.     public float rayCheckDistance;
  13.     Rigidbody2D rb;
  14.     private Animator anim;
  15.     public GameObject jumpe;
  16.  
  17.     public float scale;
  18.  
  19.  
  20.    
  21.    
  22.  
  23.     void Start()
  24.     {
  25.         rb = GetComponent<Rigidbody2D>();
  26.         anim = GetComponent<Animator>();
  27.  
  28.     }
  29.  
  30.     void FixedUpdate()
  31.     {
  32.        
  33.         float x = Input.GetAxis("Horizontal");
  34.         if (Input.GetAxis("Jump") > 0)
  35.         {
  36.             RaycastHit2D hit = Physics2D.Raycast(rayOrigin.transform.position, Vector2.down, rayCheckDistance);
  37.             if (hit.collider != null)
  38.             {
  39.                
  40.                 rb.AddForce(Vector2.up * jump, ForceMode2D.Impulse);
  41.                 anim.SetBool("jumping", true);
  42.                
  43.                 anim.SetBool("walking", false);
  44.             }
  45.         }
  46.         if (Input.GetAxis("Jump") == 0)
  47.         {
  48.             anim.SetBool("jumping",false);
  49.         }
  50.  
  51.             rb.velocity = new Vector3(x * speed, rb.velocity.y, 0);
  52.  
  53.         if (Input.GetAxis("Horizontal") != 0)
  54.         {
  55.             anim.SetBool("walking", true);
  56.            
  57.             Vector3 characterScale = transform.localScale;
  58.             if (Input.GetAxis("Horizontal") < 0)
  59.             {
  60.                 characterScale.x = -scale;
  61.             }
  62.             if (Input.GetAxis("Horizontal") > 0)
  63.             {
  64.                 characterScale.x = scale;
  65.             }
  66.             transform.localScale = characterScale;
  67.  
  68.         }
  69.         if (Input.GetAxis("Horizontal") == 0)
  70.         {
  71.             anim.SetBool("walking", false);
  72.         }
  73.  
  74.  
  75.  
  76.     }
  77.     void OnCollisionEnter2D(Collision2D other)
  78.     {
  79.        
  80.         if (other.gameObject.CompareTag("hazard"))
  81.         {
  82.  
  83.  
  84.             SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
  85.         }
  86.     }
  87.  
  88.    
  89. }
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