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 Player : MonoBehaviour
- {
- //player must have a rigidbody2D and a box colider
- public float moveSpeed = 5f;
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- Jump();
- Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
- transform.position += movement * Time.deltaTime * moveSpeed;
- }
- void Jump()
- {
- if (Input.GetButtonDown("Jump"))
- {
- gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);
- }
- }
- void Shoot()
- {
- GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
- Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
- rb.AddForce(firePoint.right * bulletSpeed, ForceMode2D.Impulse);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement