using UnityEngine;
using System.Collections;
public class RocketPropulsion : MonoBehaviour {
public float speed; //meterspersecond
public float burnTime;//How long is the rocket have thrust for?
public float spinRate;//How many rotations per second
public float velocityAtLauncherExit;//how fast does it exit the launcher
public Rigidbody rocket;//rocket rigidbody
public string firingMethod;//what input axis is being used?
public float lifeTime;
public Object toBeDestroyed;
public Transform flameStart;// transform for where to instantiate the rocket blast particles
public bool weaponSafe = true;
//Technical data for the rocketMotor
void FixedUpdate(){
if (weaponSafe = false) //This bit is firing the rocket for the burn time
{
while ( burnTime > lifeTime )
{
Rocket ();
lifeTime = lifeTime + 1 * Time.deltaTime;
}
}
if ( burnTime < lifeTime )//orienting the rocket
{
transform.rotation = Quaternion.LookRotation(rigidbody.velocity) * Quaternion.Euler (90,0,0);
//This part is making the rotation equal to the velocity of the rigidbody, the * Quaternion.Euler (90,0,0) is to adjust the rockets orientation from facing vertical to horizonal
}
}
// Use this for initialization
void Start ()
{
rigidbody.isKinematic = true;
}
// Update is called once per frame
void Rocket ()
{
rigidbody.isKinematic = false;
rocket.rigidbody.AddForce(rocket.transform.up * speed * Time.deltaTime, ForceMode.Impulse);//fires the rocket at the defined speed going in meters per second.
}
//this will make the rocket destroy any object tagged "Destroyable" You can change the tag out for anything it is just set it
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "Destroyable")
Destroy (toBeDestroyed);
lifeTime = 0; // reset it
//Instantiate(spawnBonus, transform.position, transform.rotation);
}
}
using UnityEngine;
using System.Collections;
public class MissileFireSystem : MonoBehaviour {
public GameObject[] rockets;
public string firingMethod;//what input axis is being used?
public GameObject rocket;
public int rocketToFire = 0;//refers to the rocket in the array, 0 means the first rocket
public RocketPropulsion RocketPropulsion;
// Use this for initialization
void Start () {
rockets = GameObject.FindGameObjectsWithTag("rocket#1");//getting all of the rockets, rocket#1 refers to the hydra 70 rockets
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown (firingMethod))
{
for(int i = -1; i < rocketToFire; i++)
{
rockets[rocketToFire].weaponSafe = false; //Fire rocket
rocketToFire = rocketToFire + 1;//This will move on the the next rocket.
}
}
}
}
My goal is to have the second script be able to change all the rockets and fire them via the array, and by taking off there “saftey” bool. Not sure why it wont work, specificaly the “rockets[rocketToFire].weaponSafe = false;” line
I am really not sure what to do to fix it.