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
- {
- public bool HaveBeamShot = false;
- [SerializeField]
- private GameObject _LasersPrefab;
- [SerializeField]
- private float _FireRate = 0.25f;
- private float _CanFire = 0.0f;
- [SerializeField]
- private GameObject _BeamShotPrefab;
- [SerializeField]
- private float _FireRateBeam = 1.0f;
- private float _CanFireBeam = 0.0f;
- private float _Speed = 10.0f;
- void Start()
- {
- transform.position = new Vector3(0, -2.1f, 0);
- }
- void Update()
- {
- Movement();
- if (HaveBeamShot == false)
- {
- if (Input.GetKey(KeyCode.C))
- {
- Lasers();
- }
- }
- else
- {
- if (Input.GetKey(KeyCode.C))
- {
- BeamShot();
- }
- }
- }
- void Lasers()
- {
- if (Time.time > _CanFire)
- {
- Instantiate(_LasersPrefab, transform.position + new Vector3(0, 1.1f, 0), Quaternion.identity);
- _CanFire = Time.time + _FireRate;
- }
- }
- void BeamShot()
- {
- if (Time.time > _CanFireBeam)
- {
- Instantiate(_BeamShotPrefab, transform.position + new Vector3(0, 7.2f, 0), Quaternion.identity);
- _CanFireBeam = Time.time + _FireRateBeam;
- }
- }
- void Movement()
- {
- // Horizontal movement
- float HorizontalInput = Input.GetAxis("Horizontal");
- transform.Translate(Vector3.right * _Speed * HorizontalInput * Time.deltaTime);
- // Vertical movement
- float VerticalInput = Input.GetAxis("Vertical");
- transform.Translate(Vector3.up * _Speed * VerticalInput * Time.deltaTime);
- // Bounds
- if (transform.position.y > 0)
- {
- transform.position = new Vector3(transform.position.x, 0, 0);
- }
- else if (transform.position.y < -4.2f)
- {
- transform.position = new Vector3(transform.position.x, -4.2f, 0);
- }
- // Wrap
- if (transform.position.x > 10.5f)
- {
- transform.position = new Vector3(-10.5f, transform.position.y, 0);
- }
- else if (transform.position.x < -10.5f)
- {
- transform.position = new Vector3(10.5f, transform.position.y, 0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement