Pro_Unit

Untitled

Feb 20th, 2020
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Move : MonoBehaviour
  6. {
  7.     public float horisontalSpeed;
  8.     float speedX;
  9.     public float verticalImpulse;
  10.     Rigidbody2D rb;
  11.     bool isGrounded;
  12.     void Start()
  13.     {
  14.         rb = GetComponent<Rigidbody2D>();
  15.     }
  16.     public void LeftDown()
  17.     {
  18.         speedX = -horisontalSpeed;
  19.     }
  20.     public void RightDown()
  21.     {
  22.         speedX = horisontalSpeed;
  23.     }
  24.     public void Stop()
  25.     {
  26.         speedX = 0;
  27.     }
  28.     public void OnClickJump()
  29.     {
  30.         if (isGrounded)
  31.  
  32.  
  33.  
  34.             rb.AddForce(new Vector2(0, verticalImpulse), ForceMode2D.Impulse);
  35.     }
  36.     // Update is called once per frame
  37.     void FixedUpdate()
  38.     {
  39.  
  40.         transform.Translate(speedX, 0, 0);
  41.  
  42.     }
  43.  
  44.     private void OnCollisionEnter2D(Collision2D collision)
  45.     {
  46.         if (collision.gameObject.tag == "Ground")
  47.         {
  48.             isGrounded = true;
  49.         }
  50.     }
  51.     private void OnCollisionExit2D(Collision2D collision)
  52.     {
  53.         if (collision.gameObject.tag == "Ground")
  54.         {
  55.             isGrounded = false;
  56.         }
  57.     }
  58. }
Add Comment
Please, Sign In to add comment