Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class controller : MonoBehaviour
- {
- private float MovementInput;
- public byte movementspeed;
- public float jumpforce;
- private Rigidbody2D rb;
- private BoxCollider2D col;
- private float zero;
- private float Pos;
- private float PPos;
- private float xrespawn;
- private float yrespawn;
- void Start()
- {
- movementspeed = 20;
- jumpforce = 20f;
- rb = GetComponent<Rigidbody2D>();
- col = GetComponent<BoxCollider2D>();
- Pos = rb.position.y;
- PPos = 0;
- xrespawn = 0.28f;
- yrespawn = 2.93f;
- }
- void Update()
- {
- Pos = rb.position.y;
- MovementInput = Input.GetAxisRaw("Horizontal");
- PPos = Pos;
- }
- void FixedUpdate()
- {
- Debug.Log(Mathf.Round(Pos));
- Debug.Log("And");
- Debug.Log(Mathf.Round(PPos));
- //if (Input.GetKeyDown(KeyCode.Space) && (Mathf.Round(Pos*10) == Mathf.Round(PPos*10)))
- if (Input.GetKeyDown(KeyCode.Space))
- {
- rb.velocity = Vector2.up * jumpforce;
- }
- rb.velocity = new Vector2(MovementInput * movementspeed, rb.velocity.y - 1);
- if (Pos < -20f)
- {
- rb.position = new Vector2(xrespawn , yrespawn);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement