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 Peterwerd · Feb 07, 2015 at 10:00 AM · instantiatesceneenemyloadrpg

How to tell which enemys to create in new battle scene

Hey,

I'm working on a turn based combat system. The idea is nothing new you walk along and touch an enemy's collider which triggers the battle arena (-> new scene). Now I am wondering how can I tell which enemy to instantiate inside the new scene based on the enemy I collided with. Right now I'm thinking about creating an specific "empty" gameobject (based on the enenmy I collided) that isn't destoryed on load and somehow check for it in the new battle scene and then decide which enemy should be created based on this "empty" gameobject.

But I don't really know how I could do this and got the feeling that it is probably a stupid idea and that there is a much better way to go for it, since this must be some very common thing to do for role based combat rpgs. I didn't find anything and would be thankful for pointers/ideas/concepts on how to do this (if you want to post script c# would be most useful/understandable).

Thanks a lot.

Comment
Add comment · Show 1
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 Deathdefy · Feb 10, 2015 at 12:36 AM 0
Share

Couple things you could try.

DontDestroyOnLoad(EnemyGameObject);

http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html

As a secondary idea. You could also add an additional camera to the scene and have a "battle arena" hidden until you need it and swap cameras as needed. This would remove the need for you to carry a gameobject into another scene.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by DanSuperGP · Feb 10, 2015 at 12:41 AM

"Right now I'm thinking about creating an specific "empty" gameobject (based on the enenmy I collided) that isn't destoryed on load and somehow check for it in the new battle scene and then decide which enemy should be created based on this "empty" gameobject."

This isn't a bad idea.

If you want data to persist between scenes, the easy way to do it is to make a manager that's set to http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html

Then, when you collide with an enemy and you transition between scenes... you can tell that manager important data... like which units to spawn for the enemy, and where on the world map you were when the fight started so you can place the player back in the same spot when the fight is over...

And all sorts of other stuff.

Comment
Add comment · Show 4 · 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 Peterwerd · Feb 10, 2015 at 10:50 AM 0
Share

Hey Thanks, for your answer. I already have a GameInformation object which is set to DontDestroyOnLoad. At the moment I only save my players stats in it. Would you use this also to save other information in it? So the idea would be: on collision put data in the GameInformation -> In the battle scene I have a gameObject with a script on it that does different things depending on what was set in the GameInformation? Sounds like I wont need to create a gameobject on collision like my original idea, am I right?

avatar image DanSuperGP · Feb 10, 2015 at 05:34 PM 0
Share

Yeah, you could use the same object, or you could create others.

I could see creating a temporary do not destroy on load object when a fight is triggered... but then taking the data from it and destroying it before going to the map, ins$$anonymous$$d of overloading the GameInformation you already have.

Either way will work fine.

avatar image Peterwerd · Feb 16, 2015 at 10:29 PM 0
Share

Hey Dan, just wanted to let you know. After some noob struggles I finaly got what I wanted. The Collider checks for other colliders inside it that are on the layer enemy. This way I create an array of all enemys inside the collider. From this array I create another string array that stores the typeOfEnemy string that each enemy has. This gets send to the EnemyInfoTemp which is created the moment the player triggers the collider and is set to don't destroy on load.

In the new loaded battle scene. I check the saved string array in the EnemyInfoTemp with a foreach loop and instantiate the right enemy for each string in the array.

Tada it works :) program$$anonymous$$g drives me crazy but when it finaly works it's awesome!!

avatar image DanSuperGP · Feb 16, 2015 at 11:19 PM 0
Share

Yeah when it works, that's the best feeling ever

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to get the position of a new Instantiated prefab 1 Answer

Load Player Position Problem 2 Answers

Instantiate Explosion Position 2 Answers

HELP Game Scene 8 (-1) Cannot be loaded because it has not been added to the build settings 1 Answer

Enemy Targetting Help 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