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 AKJ9 · Apr 28, 2014 at 02:43 PM · instantiateenemysetactivewaypointactive

Activating a 'boss' in the scene once all enemies are destroyed

Hi all,

I've been doing A LOT of reading as to how I can get my 'boss' to appear once all the mini enemies are destroyed. Initially, I successfully achieved this via instantiation, but then could not get my instantiated boss to follow waypoints like my other enemies (you can see my initial question **here** in case you have an answer for it).

Having tried a lot of methods to accomplish this (and failing), I've decided to change the way this works and use SetActive() to make my boss appear instead of instantiating him. Using this will enable me to assign waypoints to him a lot easier. I've been doing a lot of research on this and have tried several solutions, but encountering the following problem. I am able to deactivate my boss on startup, but cannot activate him once all enemies are destroyed.

Here is my EnemyDead.js script (which is attached to all four enemies in the scene):

 public static var enemyCount : int = 4;
 GameObject.Find("boss").SetActive(false);
 
 function OnCollisionEnter( collision : Collision ) 
 
  {
 
       if(collision.gameObject.tag == "fireball")
 
       {
       animation.Play("dying");
       audio.Play();
  yield WaitForSeconds(0.2);
          GameObject.Destroy ( gameObject ) ;
 
          enemyCount -= 1;
 }
 if(enemyCount <= 0) {
 
 GameObject.Find("boss").SetActive(true);
 
   }}
 

We can see here that if all enemies are destroyed, the boss should load. However, he does not. I've read that you cannot use GameObject.Find("string") to activate an object that's been deactivated, but cannot find an alternate route around this.

I've tried .active, SetActiveRecursively, activeSelf, activeInHierarchy - the lot. For your information, I am using Unity 4. Any support or guidance would be much appreciated. Apologies if this is such a simple question, I can't get my head around it!

Many thanks for your time in advance!

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 TheRaven · Apr 29, 2014 at 07:13 AM

Basically if the object is not enabled then the find function wont find it (Which I have found very annoying). You can create some other way to disable it such as a local variable like "isAlive" or something, therefore never setting it to disabled or you could store a pointer to a boss enitiy before turning the entity off. The problem isn't activating a disabled entity. The problem is using the find function to get access to it.

Comment
Add comment · Show 1 · 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
avatar image AKJ9 · May 06, 2014 at 08:04 PM 0
Share

@TheRaven right I see where you're co$$anonymous$$g from. I still haven't had much luck with this. Do you think you could assist me with some code examples? $$anonymous$$any thanks for your time.

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

21 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Assigning Waypoints to an instantiated enemy 1 Answer

NavMesh giving jerky like motion 0 Answers

Make object move in a direction depending on where it spawns? (C#) 1 Answer

activate GameObject dont work 1 Answer

instantiated objects animation making the object reset to 0,0,0?? 1 Answer


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