Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Prophet93 · May 02, 2013 at 07:30 AM · bce0019

BCE0019 Error

Hey guys, the problem is as above and is the following:

  1. Assets/Scripts/Enemy.js(53,24): BCE0019: 'multiplier' is not a member of 'UnityEngine.GameObject'.

  2. Assets/Scripts/Enemy.js(55,24): BCE0019: 'multiplier' is not a member of 'UnityEngine.GameObject'.

  3. 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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Accessing functions in other scripts. 1 Answer

Pragma Strict Question/Problem 1 Answer

Missile script is suddenly giving errors 1 Answer

How to import the object from server to unity 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges