Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed May 20, 2019 at 05:00 PM by Porcus for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Porcus · Nov 05, 2017 at 06:17 PM · unity 5oncollisionadventure

Carry Object over multiple scenes - Adventure Game

Hello everyone,

I try to make an adventure game like the good old LucasArts games.

I have got the movement for my character, but now I don't know how to continue: My character should obtain a tagged gameobject (e.g. "Object1") with OnCollision2D and should be able to carry this object over multiple scenes until the player presses the M key. Then the character should release this object (the item should spawn next to him).

The problem is it's the first time I try to make this and I have no clue. If anyone has an idea or a script, I would be very grateful.

Thanks.

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

  • Sort: 
avatar image
0

Answer by TanselAltinel · Nov 05, 2017 at 07:12 PM

Hi Porcus,

What you need is DontDestroyOnLoad

Then you can enable or disable the same object as long as it is needed. You don't need to spawn it as it will be there all the time, but you can deactivate it whenever you don't need it (or don't want to be seen on the screen).


Here's the documentation on the code: https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html


And here's a nice official documentation about Data Persistence: https://unity3d.com/learn/tutorials/topics/scripting/persistence-saving-and-loading-data

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 Darkwinger · Nov 05, 2017 at 07:50 PM 0
Share

You would also need some way to make sure to keep the object where you left it when you leave the scene and then return back to it. I would suggest using Player Prefs to save a bool that says this object is in this scene. Then when entering the scene you check if the object is in the scene and if it is you load in the coordinates of that object (also saved using PlayerPrefs). You could also try keeping a note of which scene the object is left in, and keep using DontDestroyOnLoad, but when the object isn't supposed to be in the scene it's deactivated so it can't be scene and when you return to that place it's is activated again. (But it is never destroyed)

Follow this Question

Answers Answers and Comments

148 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 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 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 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 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 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 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

Can't play video in Adventure Creator: "On standalone, this Action is only available in Unity 5 or Unity Pro." 0 Answers

Player Smoothness across network (PUN) 0 Answers

Unity 5 Crashing After Opening Project 1 Answer

Shader to dilate a binary image 2 Answers

Mesh Collider didn't work unless i walk slowly towards it 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