Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerController : MonoBehaviour
- {
- [SerializeField] float speed = 2;
- [SerializeField] float jumpPower = 5;
- Rigidbody2D rigidbody2D;
- float moving;
- // Start is called before the first frame update
- void Start()
- {
- rigidbody2D = GetComponent<Rigidbody2D>();
- }
- // Update is called once per frame
- void Update()
- {
- moving = Input.GetAxis("Horizontal");
- transform.position += new Vector3(speed * Time.deltaTime * moving, 0, 0);
- if (Input.GetKeyDown(KeyCode.Space))
- {
- Jump();
- }
- }
- void Jump()
- {
- rigidbody2D.AddForce(transform.up * jumpPower, ForceMode2D.Impulse);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment