Hey!
I have this script i want to use, if its possible.
The first thing i want to ask if its possible to put a delay on when the cannon fired, depending on when the player presses the fire button.
Like a charging time delay.
second.
Do i have to make another script if i want to have two different guns on one player model?
for instance:
I have a sci fi Tank that shoots a slow moving but deadly charged plasma shot that takes out an area of enemies.
but there is a secondary laser minigun you can use.
any pointers on how to make that?
using UnityEngine;
public class PlayerShooting : MonoBehaviour
{
public int damagePerShot = 20;
public float timeBetweenBullets = 0.15f;
public float range = 100f;
float timer;
Ray shootRay;
RaycastHit shootHit;
int shootableMask;
ParticleSystem gunParticles;
LineRenderer gunLine;
AudioSource gunAudio;
Light gunLight;
float effectsDisplayTime = 0.2f;
void Awake ()
{
shootableMask = LayerMask.GetMask (“Shootable”);
gunParticles = GetComponent ();
gunLine = GetComponent ();
gunAudio = GetComponent ();
gunLight = GetComponent ();
}
void Update ()
{
timer += Time.deltaTime;
if(Input.GetButton (“Fire1”) && timer >= timeBetweenBullets && Time.timeScale != 0)
{
Shoot ();
}
if(timer >= timeBetweenBullets * effectsDisplayTime)
{
DisableEffects ();
}
}
public void DisableEffects ()
{
gunLine.enabled = false;
gunLight.enabled = false;
}
void Shoot ()
{
timer = 0f;
gunAudio.Play ();
gunLight.enabled = true;
gunParticles.Stop ();
gunParticles.Play ();
gunLine.enabled = true;
gunLine.SetPosition (0, transform.position);
shootRay.origin = transform.position;
shootRay.direction = transform.forward;
if(Physics.Raycast (shootRay, out shootHit, range, shootableMask))
{
EnemyHealth enemyHealth = shootHit.collider.GetComponent ();
if(enemyHealth != null)
{
enemyHealth.TakeDamage (damagePerShot, shootHit.point);
}
gunLine.SetPosition (1, shootHit.point);
}
else
{
gunLine.SetPosition (1, shootRay.origin + shootRay.direction * range);
}
}
}