forked from Syntax-Error/ArenaShooter
Removed Visual Studio stuff, because metadata files were not uploaded correctly
32 lines
No EOL
892 B
C#
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;
|
|
}
|
|
} |