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
1
Question by noporcru · May 02, 2014 at 05:38 AM · playerspawndirectiontransitionfacing

Player spawns facing the wrong direction.

I am making an fps and when I walk up and down stairs, it changes levels (scenes). I made it so it keeps all of the player and menu info saved so that when it loads into the next scene it is the same. However, going from room 1 to room 2, the player spawns facing the door to the stairs he just came from, yet if I go back to room 1 from room 2, he faces the rest of the room and not the door he came from, which is what I want for the first situation. Here's the code for transition:

public class LevelTransition : MonoBehaviour { public string LevelName = string.Empty; public string SpawnName = string.Empty;

 public GameObject Player;
 public GameObject GameUI;
 public GameObject MenuAnchor;
 public GameObject Minimap;

 public void OnTriggerEnter(Collider collision)
 {
     if (collision.tag == "Player")
     {
         Transition();
     }
 }

 void Awake()
 {
     Player = GameObject.Find("Player");
     GameUI = GameObject.Find("Game UI");
     MenuAnchor = GameObject.Find("Menu Anchor");
     Minimap = GameObject.Find("Minimap");
 }

 void OnClick()
 {
     Player.SetActive(true);
     Minimap.SetActive(true);
     Minimap.GetComponent<Camera>().depth = 5f;
     NGUITools.SetActive(GameUI, true);
     NGUITools.SetActive(MenuAnchor, true);

     Transition();
 }

 void Transition()
 {
     DontDestroyOnLoad(this.gameObject);
     Application.LoadLevel(LevelName);
     LoadedResources.ReloadAll();

     Screen.lockCursor = true;
 }

}

this is probably so simple to do but I'm blanking please and thanks for the help.

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

2 Replies

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

Answer by jeebxoxo · May 02, 2014 at 01:59 PM

Okay for one thing I'm not sure you need to call DontDestroyOnLoad(this.gameObject); every time you do a transition, you should be able to call that once on a script on your player and it should be good to go the rest of the game.

So what I would do here is add a var to your player on a script somewhere that saves the 'lastLevel' you were on. You could save that any way you want, let's say it's just an int and you load up level 1. Set lastLevel to 1.

Then when you load level two, you could add something in a Start() method that looks for your player GameObject and then gets that lastLevel variable. Then you could set up a switch() statement to set the position and rotation of your player, then set the lastLevel to the new level you just loaded.

So something like creating a LevelManager script on your player and then check/set the variable:

 void Start() {
 
 Player = GameObject.Find("Player");
 int lastLevel = Player.GetComponent<LevelManager>().lastLevel;
 
 switch (lastLevel) {
 default:
 break;
 case 1:
 // set your player position and rotation here
 break;
 case 2:
 break;
 //etc etc 
 }

 // then set the lastLevel int to your new level here
 }


Your Player is a prefab right? You should be able to test directly in your scene by loading it up in your editor and then dropping your player in. You could then set the lastLevel manually that way you could test the different directions / scenarios.

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 noporcru · May 02, 2014 at 02:25 PM 0
Share

Ahaha woah you just blew my $$anonymous$$d thanks a lot man, I will most definitely try this out. Great answer, it's appreciated.

avatar image jeebxoxo · May 02, 2014 at 02:31 PM 0
Share

I'm happy to help! I hope you make an awesome game. Good luck!

avatar image
0

Answer by eshonbel · May 02, 2014 at 07:36 AM

On the scene, try rotating your Player Game Object where it begins.

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 noporcru · May 02, 2014 at 01:37 PM 0
Share

I can't because in the scene there is no player to start, the player spawns from the scene before it, this is to keep things like health and spells and mana and such the same as the scene before it. So if I just go to the scene that I'm having the problem on, there won't be a player, just the level.

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

spawn points/ player transition from level to level with multiple exits and entrances 3 Answers

move particle direction with player 1 Answer

rotating ray with player rotation. 2 Answers

How do I move a CharacterController type in the direction it's facing? 1 Answer

Player Spawn problems 2 Answers


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