The problem with the below code is that it only works once and I want it to work every time the ship dies.
I have a health script on my ship that has a the fallowing code for the resawn. This script is longer but this is the part that does it. destroyed is called.
void destroyed()
{
Destroy (GameObject.Find("Guns"),1);
animation.wrapMode = WrapMode.Once;
animation.wrapMode = WrapMode.Once;
animation["LeftWing"].wrapMode = WrapMode.Once;
animation["LeftWing"].layer = 3;
animation.Play ("LeftWing");
Destroy (GameObject.Find("Left_Wing"),3);
animation.wrapMode = WrapMode.Once;
animation["RightWing"].wrapMode = WrapMode.Once;
animation["RightWing"].layer = 4;
animation.Play ("RightWing");
Destroy (GameObject.Find("Right_Wing"),3);
animation.wrapMode = WrapMode.Once;
animation["RightThruster"].wrapMode = WrapMode.Once;
animation["RightThruster"].layer = 5;
animation.Play ("RightThruster");
Destroy (GameObject.Find("Right_Engine"),3);
animation.wrapMode = WrapMode.Once;
animation["LeftThruster"].wrapMode = WrapMode.Once;
animation["LeftThruster"].layer = 6;
animation.Play ("LeftThruster");
Destroy (GameObject.Find("Left_Engine"),3);
animation.wrapMode = WrapMode.Once;
animation["WindowBlowoff"].wrapMode = WrapMode.Once;
animation["WindowBlowoff"].layer = 7;
animation.Play ("WindowBlowoff");
Destroy (GameObject.Find("Window"),3);
animation.wrapMode = WrapMode.Once;
animation["WindowFrameBlowoff"].wrapMode = WrapMode.Once;
animation["WindowFrameBlowoff"].layer = 8;
animation.Play ("WindowFrameBlowoff");
Destroy (GameObject.Find("Window_Frame"),3);
WingDamage.SetActive(false);
WingDamage2.SetActive(false);
Destroy (GameObject.Find("Star Blaster"),4);
Destroy (GameObject.Find ("Star Blaster(Clone)"),4);
GameObject varGameObject = GameObject.Find("Main Camera"); // Finds the main ship
varGameObject.GetComponent<CameraFollow>().enabled = false; // Finds the fly script and turns it off if we die
curShipHealth = 0;
texture.GetComponent<AddDamage>().thirdDamage = true; // Finds the fly script and turns it off if we die
MassDamage.SetActive(true);
explosion.SetActive(true);
player.GetComponent<ShipThrusterControle>().level3 = true; // Finds the fly script and turns it off if we die
// texture.GetComponent<AddDamage>().firstDamage = false; // Finds the fly script and turns it off if we die
// texture.GetComponent<AddDamage>().secondDamage = false; // Finds the fly script and turns it off if we die
// texture.GetComponent<AddDamage>().thirdDamage = false; // Finds the fly script and turns it off if we die
// texture.GetComponent<AddDamage>().Dead = false; // Finds the fly script and turns it off if we die
//
// texture.GetComponent<AddDamage>().Repair = true; // Finds the fly script and turns it off if we die
// texture.GetComponent<AddDamage>().Repair = false; // Finds the fly script and turns it off if we die
curShipHealth = 100;
StartCoroutine(Respawn());
}
IEnumerator Respawn()
{
yield return new WaitForSeconds (3);
myShip.SetActive (false);
GameObject varGameObject = GameObject.Find("Main Camera"); // Finds the main ship
Spawn respawn = varGameObject.GetComponent<Spawn>(); // Finds the fly script and turns it off if we die
respawn.enabled = true;
respawn.dead = true;
}
This turns on a script I have on my main camera that I am trying to use to respawn the ship.
This code:
using UnityEngine;
using System.Collections;
public class Spawn : MonoBehaviour
{
public Transform ship;
public Transform location1; // The teleport after death location
private Transform newShip;
public bool dead = false;
void Start ()
{
Dead();
}
void Dead()
{
if(dead)
{
GameObject clone = Instantiate (ship, location1.position, location1.rotation)as GameObject;
newShip = GameObject.FindWithTag("Player").transform;
GameObject varGameObject = GameObject.Find("Main Camera");
CameraFollow cameraFollow = varGameObject.GetComponent<CameraFollow>();
ShipHealth health = varGameObject.GetComponent<ShipHealth>();
cameraFollow.enabled = true;
cameraFollow.target = newShip;
dead = false;
varGameObject.GetComponent<Spawn>().enabled = false; // Finds the fly script and turns it off if we die
}
}
}