- Home /
BCE0019 Error
Hey guys, the problem is as above and is the following:
Assets/Scripts/Enemy.js(53,24): BCE0019: 'multiplier' is not a member of 'UnityEngine.GameObject'.
Assets/Scripts/Enemy.js(55,24): BCE0019: 'multiplier' is not a member of 'UnityEngine.GameObject'.
Assets/Scripts/Enemy.js(58,21): BCE0019: 'lastEnemyDestroyedColor' is not a member of 'GameManager'. Did you mean 'lastEnemyDestroyed'?
Now I should tell you about the game. Basically it's a SHMUP that when enemies spawn they will be one of 3 colours (r,g,b). You will get a multiplier for killing more of the same color in a row (ie 3 blues in a row is a multiplier of 3), also hitting a new color breaks the chain.
Here is my GameManager.js:
// The Game Manager is an invisible Game Object which manages generic stuff like
// keeping track of bullets, spawning enemies, scoring, the GUI etc...
#pragma strict
import System.Collections.Generic; // allows use of stacks
var playerBullet : Bullet; // link to the bullet prefab
var enemyBullet : Bullet; // prefab link
var enemy : Enemy; // enemy prefab
var player : Player; // link to the player
var multiplier : int;
static var playerBulletStack = new Stack.<Bullet>(); // a stack to store all the player bullets
static var enemyBulletStack = new Stack.<Bullet>(); // a stack to store all the enemy bullets
static var lastEnemyDestroyed : int;
static var score : int = 0; // counts how many enemies have been killed
static var lives : int = 5; // how many lives the player has left
var btnTexture1 : Texture;
function Start ()
{
// create bullets for the player and store them in a stack
// this is faster than instantiating them when the player shoots
for (var i = 0; i < 10; i++)
{
var newBullet = Instantiate (playerBullet, Vector3.zero, Quaternion.identity); // create a bullet
newBullet.gameObject.active = false; // disable it until it's needed
playerBulletStack.Push(newBullet); // put it on the stack
}
// create bullets for enemies
// creating way more than needed, because in a game like this it's good to have lots of enemy bullets
for (var j = 0; j < 20; j++)
{
var newEnemyBullet = Instantiate (enemyBullet, Vector3.zero, Quaternion.identity); // create a bullet
newEnemyBullet.gameObject.active = false; // disable it until it's needed
enemyBulletStack.Push(newEnemyBullet); // put it on the stack
}
SendEnemies();
}
function Update ()
{
}
function OnGUI ()
{
GUI.Box(Rect(10, 10, 80, 20), "Score: " + score);
GUI.Box(Rect(10, 40, 80, 20), "Lives: " + lives);
}
function SendEnemies() // sends waves of enemies
{
SpawnEnemy(0);
yield WaitForSeconds(1);
SpawnEnemy(0);
yield WaitForSeconds(1);
SpawnEnemy(0);
yield WaitForSeconds(0.5); // wait longer between waves
SpawnEnemy(4);
yield WaitForSeconds(1);
SpawnEnemy(4);
yield WaitForSeconds(1);
SpawnEnemy(4);
yield WaitForSeconds(0.5); // wait longer between waves
SpawnEnemy(-3);
yield WaitForSeconds(1);
SpawnEnemy(-3);
yield WaitForSeconds(1);
SpawnEnemy(-3);
yield WaitForSeconds(1);
}
function SpawnEnemy (xSpawn : float) : IEnumerator // the IEnumerator here allows this function to call itself
{
// spawn an enemy off screen at a random X position
var newEnemy : Enemy = Instantiate (enemy, Vector3(xSpawn, 0, 10), Quaternion.identity);
var randomColor = Random.Range(0, 3);
switch (randomColor)
{
case 0:
newEnemy.renderer.material.color = Color.red; //Spawns enemies either red, blue or green
break;
case 1:
newEnemy.renderer.material.color = Color.green; //Spawns enemies either red, blue or green
break;
case 2:
newEnemy.renderer.material.color = Color.blue; //Spawns enemies either red, blue or green'
break;
}
// move it and tell it to shoot in a random time
newEnemy.motion = new Vector3(0, 0, -3);
var shootDelay = Random.Range(0.5, 2.0);
newEnemy.Shoot(shootDelay); // waits a few seconds then shoots
// destroy it in 7 seconds (it will be off-screen by then if the player hasn't killed it)
Destroy(newEnemy.gameObject, 7);
}
Following now is my Enemy.js:
#pragma strict
var hitPoints : int; // assigned when the enemy spawns
var motion : Vector3; // assigned when the enemy spawns
var myTransform : Transform;
var gameManager : GameObject;
var randomColor;
var enemyColor : int;
static var multiplier : int;
static var lastEnemyDestroyedColor : int;
static var enemyBulletSpeed : float = 5;
function Start ()
{
myTransform = transform; // cached for performance
gameManager = GameObject.Find("GameManager"); // store the game manager for accessing its functions
}
function Update ()
{
// move
myTransform.position += (motion * Time.deltaTime);
}
function OnTriggerEnter(other : Collider)
{
if (other.CompareTag("PlayerBullet")) // hit by a bullet
{
TakeDamage(1); // take away 1 hit point
// disable the bullet and put it back on its stack
other.gameObject.active = false;
gameManager.GetComponent(GameManager).playerBulletStack.Push(other.GetComponent(Bullet));
}
}
function TakeDamage(damage : int)
{
// subtract damage and check if it's dead
hitPoints -= damage;
if (hitPoints <= 0)
Explode();
}
function Explode() // destroy this enemy
{
// draw particle explosion effect
// play sound
Destroy(this.gameObject);
if (enemyColor == lastEnemyDestroyedColor)
gameManager.multiplier++;
else
gameManager.multiplier = 1;
GameManager.score += multiplier; // or this enemy's points value multiplied by the multiplier
GameManager.lastEnemyDestroyedColor = enemyColor; // saves this color for the next check
// increment the score
gameManager.GetComponent(GameManager).score++;
}
function Shoot(delay : float) // waits for 'delay' seconds, then shoots directly at the player
{
yield WaitForSeconds(delay);
// get a bullet from the stack
var newBullet = gameManager.GetComponent(GameManager).enemyBulletStack.Pop();
// position and enable it
newBullet.gameObject.transform.position = myTransform.position;
newBullet.gameObject.active = true;
// calculate the direction to the player
var shootVector = gameManager.GetComponent(GameManager).player.transform.position - myTransform.position;
// normalize this vector (make it length 1)
shootVector.Normalize();
// scale it up to the correct speed
shootVector *= enemyBulletSpeed;
newBullet.motion = shootVector;
}
Anyway guys, any help would be greatly appreciated. I am still very new to Unity, so the simplest answer would be great. Cheers
Answer by whydoidoit · May 02, 2013 at 07:33 AM
Well firstly you need to define
var gameManager : GameManager;
Then when you find it:
gameManager = GameObject.Find("GameManager").GetComponent(GameManager);
Then it's right - GameManager doesn't have a lastEnemyDestroyedColor - you would have to define it.