I have two scripts. One accounts for one shooter and the other accounts for multiple shooters. I feel that having both of these is redundant. So what would be best resource wise, using multiple instances of the first script or use the second script once for the gameobjects with only one shooter?
using UnityEngine;
using System.Collections;
public class PlayerShooter: MonoBehaviour
{
//Public Var
public GameObject shotGO; //Fire Prefab
public float baseFireRate; //Fire Rate between Shots
public float fireRate = 0.5F; //Fire Rate between Shots
//Private Var
private float nextFire = 0.0F; //First fire & Next fire Time
void Start()
{
baseFireRate = fireRate;
}
void Update ()
{
//Excute When the Current Time is bigger than the nextFire time
if (Input.GetMouseButton(0)){
if (Time.time > nextFire)
{
nextFire = Time.time + fireRate; //Increment nextFire time with the current system time + fireRate
Instantiate (shotGO , transform.position ,transform.rotation); //Instantiate fire shotGO
GetComponent<AudioSource>().Play(); //Play Fire sound
}
}
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PlayerShooterMulti: MonoBehaviour
{
//Public Var
public List<Transform> shotPositions;
public GameObject shotGO; //Fire Prefab
public float baseFireRate; //Fire Rate between Shots
public float fireRate = 0.5F; //Fire Rate between Shots
//Private Var
public float nextFire = 0.0F; //First fire & Next fire Time
void Start()
{
baseFireRate = fireRate;
}
void Update ()
{
//Excute When the Current Time is bigger than the nextFire time
if (Input.GetMouseButton(0)){
if (Time.time > nextFire)
{
nextFire = Time.time + fireRate; //Increment nextFire time with the current system time + fireRate
for (int i = 0; i < shotPositions.Count; i++){
Instantiate (shotGO , shotPositions_.position ,shotPositions*.rotation); //Instantiate fire shotGO*_
* }*
* GetComponent().Play(); //Play Fire sound*
* }*
* }*
* }*
}