Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Move : MonoBehaviour
- {
- public float horisontalSpeed;
- float speedX;
- public float verticalImpulse;
- Rigidbody2D rb;
- bool isGrounded;
- void Start()
- {
- rb = GetComponent<Rigidbody2D>();
- }
- public void LeftDown()
- {
- speedX = -horisontalSpeed;
- }
- public void RightDown()
- {
- speedX = horisontalSpeed;
- }
- public void Stop()
- {
- speedX = 0;
- }
- public void OnClickJump()
- {
- if (isGrounded)
- rb.AddForce(new Vector2(0, verticalImpulse), ForceMode2D.Impulse);
- }
- // Update is called once per frame
- void FixedUpdate()
- {
- transform.Translate(speedX, 0, 0);
- }
- private void OnCollisionEnter2D(Collision2D collision)
- {
- if (collision.gameObject.tag == "Ground")
- {
- isGrounded = true;
- }
- }
- private void OnCollisionExit2D(Collision2D collision)
- {
- if (collision.gameObject.tag == "Ground")
- {
- isGrounded = false;
- }
- }
- }
Add Comment
Please, Sign In to add comment