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 MasonEntrican · Mar 07, 2014 at 06:10 AM · c#booleanspawninginheritance

[C#] How to spawn multiple objects that share the same base-class

My Problem: I don't know where to set my bool spawnFlag to false. If I set it within my base-class, only one object is respawned properly. If I don't set it at all, with every update all the objects are respawned (which means technically the respawn logic itself is working, but it needs to stop after the respawn of those objects). I may have gone about this all wrong, but with how I have it laid out currently, I just need to figure out how to properly end the spawning of the objects inheriting my classObject base-class once my main character spawn triggers.

I have a GameManager class that has a method to spawn the main character.

 public void SpawnPlayer(Vector3 spawnPos) {
         spawnFlag = true;
         currentPlayer = (Instantiate(player,spawnPos,Quaternion.identity) as GameObject);
         cam.SetTarget(currentPlayer.transform);
     }




The other characters need to be respawned at their default spawn position upon respawn of the player. The other characters inherit the base-class 'classObject'. Within this is a method that is called in the Update() of the sub-class to allow respawning.

     //Clears trigger flag and sets position to default
     public void AllowRespawn() {
         if (gm.spawnFlag) {
             Debug.Log("Respawning Object: " + this.gameObject);
             isTriggered = false;
             transform.Translate(Vector3.zero);
             transform.position = spawnPos;
         }
     }
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
1

Answer by Jiro-Ng · Mar 07, 2014 at 08:08 AM

I think the re-spawning need to perform by the Game Manager or the base class but not withing the character itself. You can try to do in Game Manager. When spawnFlag is true, find all character object, then respawn with a for or foreach loop. This is just my suggestion. Hope this fits your game.

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 Berenger · Mar 07, 2014 at 08:26 AM 0
Share

Sounds about right. I don't see any use for the spawnFlag here. Just give the game manager control over all your instances.

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

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

Related Questions

An OS design issue: File types associated with their appropriate programs 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Same script working on one object at a time. 1 Answer

Passing arguments to base constructor fails 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