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 FableGames · Aug 30, 2014 at 07:05 PM · triggerplayersceneloadapplication

Loading player location in a scene

I am working on a game with multiple rooms and scenes. When you go through a door, a new scene loads in the next room, but when you go back through the same door to the previous room, I have to use an entirely new duplicate scene with an altered player position in front of that door. The whole system is controlled by triggers activated by GameObject colliders with a specific name.

Instead of having up to 14 identical scenes with different player locations, is there a way that I only have to have 1 scene per room?

In other words, when you go back through a door, can I load the same scene, but change the player location according to the door you just came from?

I hope what I am asking makes sense. I've tried googling and the Unity Forums but haven't found a suitable answer. Any help would be greatly appreciated. Thank you.

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 SuuKoolGaming · Jan 14, 2015 at 01:45 AM 0
Share

smashes head into keys Okay so after hours or coding, debugging, googling. Screw it I think Fable had it right, I'm just going to make duplicate scenes with different data in a progression. WHY IS IT SO HARD TO $$anonymous$$A$$anonymous$$E A JAVASCRIPT THAT TRAC$$anonymous$$S PLAYER POSITION IN-BETWEEN ALL SCENES.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by TwitchBlade · Aug 30, 2014 at 07:22 PM

Could you save something in Player prefs like and in and say character one came from scene 2 through door three then when you load the scene just check and see where the player pos should be on load

 using UnityEngine;
 using System.Collections;
 
 public class test : MonoBehaviour {
 
     public GameObject player;
 
     private bool newRoom;
     private int prevDoor;
     private int prevRoom;
 
     // Use this for initialization
     void Start () {
         prevDoor = PlayerPrefs.GetInt("prevDoor");
         prevRoom = PlayerPrefs.GetInt("prevRoom");
 //        predefined location
         player.transform.position = Vector3();
     
     }
     
     // Update is called once per frame
     void Update () {
 
         //saveing which door and room you went to
         if (/*player walks through door*/ newRoom)
         {
             PlayerPrefs.SetInt("prevDoor",3);
             PlayerPrefs.SetInt("prevRoom",2);
         }
         Application.LoadLevel(level);
     }
 }
 

something like that

Comment
Add comment · Show 2 · 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 FableGames · Aug 30, 2014 at 07:25 PM 0
Share

I have no experience with PlayerPrefs. I have tried using it before, but not in this instance. I honestly spent 2 months trying to get PlayerPrefs to work by watch tutorials, visiting the Docs, and the Unity Community. I can't get it right, haha. Basically, I'm trying to avoid PlayerPrefs for now if I can. I'll give it a fair try though.

avatar image FableGames · Aug 30, 2014 at 08:31 PM 0
Share

Unfortunately it didn't work.

avatar image
0

Answer by GraviterX · Aug 30, 2014 at 09:15 PM

The only way to make this easier that I know of is to make animations and use scripting to open the doors. Then you can have multiple rooms in one scene.

I will include my script below. Add a trigger around the door. The player has to stand inside this trigger in order to open the door. You can also add an audiosource to make a sound play when they open the door. Also, rename the animation to your animation name.

 var AudioFile : AudioClip;
      
 function OnTriggerStay (other : Collider) {
 if (Input.GetButtonDown("Fire1")){
 animation.Play("door");
 audio.clip = AudioFile;
 audio.Play();
 }
 }

I hope this helps.

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 FableGames · Aug 30, 2014 at 11:04 PM 0
Share

Thank you. I've been considering trying this. I'll let you know if it works out for me. Thank you again.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Loading player location in the same scene 3 Answers

Click Object to change scene 2 Answers

Restarting a Scene 1 Answer

Network - Load For Late Players 1 Answer

carrying player data from one scene to the next 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