ArenaShooter/Assets/ProjectileShoot.cs
Balazs Toldi 27114e4d86
Fixed git ignore
Removed Visual Studio stuff, because metadata files were not uploaded correctly
2021-06-22 20:29:23 +02:00

32 lines
No EOL
892 B
C#

using UnityEngine;
public class ProjectileShoot : MonoBehaviour {
public bool automatic = false;
public GameObject bullet;
public Camera camera;
public float damage = 10f;
public float fireRate = 2f;
private float nextTimeToFire;
public ParticleSystem particle;
public float range = 100f;
private void Update() {
if (automatic) {
if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire) shoot();
}
else {
if (Input.GetButtonDown("Fire1") && Time.time >= nextTimeToFire) shoot();
}
}
protected virtual void shoot() {
particle.Play();
GameObject clone = Instantiate(bullet, transform.position, Quaternion.LookRotation(-camera.transform.forward) );
clone.transform.forward = camera.transform.forward;
nextTimeToFire = Time.time + 1f / fireRate;
}
}