Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlayerMovement : MonoBehaviour
- {
- public float speed;
- private Rigidbody2D rigidbody;
- void Start()
- {
- rigidbody = GetComponent<Rigidbody2D>();
- }
- void Update()
- {
- Movement();
- }
- void Movement()
- {
- if (Input.GetKey(KeyCode.A))
- {
- transform.Translate(-speed * Time.deltaTime, 0, 0);
- }
- else if (Input.GetKey(KeyCode.D))
- {
- transform.Translate(speed * Time.deltaTime, 0, 0);
- }
- }
- void OnCollisionEnter2D(Collision2D other)
- {
- if (other.gameObject.tag == "Platform")
- {
- rigidbody.AddForce(new Vector2(0f, 500f));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement