- Home /
Items scripted in enemy script but don't appear.
Another question I have... I have items scripted as an array but when the enemy is destroyed the items don't appear... or rather they appear in the hierarchy as clones but do not display in game play.
Below is that script also. Any assistance would be amazing.
Thank you all in advance.
using UnityEngine; using System.Collections;
public class enemyController : MonoBehaviour {
public int lives;
public GameObject [] Items;
public GameObject drop;
public GameObject explosion;
public GameObject playerExplosion;
public int scoreValue;
private GameController GameController;
void Start ()
{
Items = new GameObject[3];
for (int i = 0; i < 3; i++)
{
GameObject go = Instantiate (drop, transform.position, Quaternion.identity) as GameObject;
go.transform.localScale = Vector3.one;
Items [i] = go;
}
//Items [0] = "null";
//Items [1] = "MG";
//Items [2] = "L";
GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
if (gameControllerObject != null)
{
GameController = gameControllerObject.GetComponent <GameController>();
}
if (GameController == null)
{
Debug.Log ("cannot find 'GameController' script");
}
}
void OnTriggerEnter(Collider other) {
if (other.tag == "Boundary")
{
return;
}
if (other.tag == "eBullet")
{
//Debug.Log ("friendly fire")
return;
}
if (other.tag == "Enemy")
{
return;
}
if (other.tag == "pBullet") {
Instantiate (explosion, transform.position, transform.rotation);
lives -= 1;
if (lives <= 0)
{
Instantiate (Items [Random.Range (0,2)]);//Instantiate (Items [1], transform.position, Quaternion.identity) as GameObject;
Destroy (gameObject);
}
}
if (other.tag == "Player")
{
Instantiate (playerExplosion, other.transform.position, other.transform.rotation);
Destroy (gameObject);
{
//Application.LoadLevel ("GameOver");//GameController.GameOver ();
}
GameController.AddScore (scoreValue);
}
} }
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Activate an input to pickup or search objectes 1 Answer
Implementation of Items 0 Answers