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 /
  • Help Room /
avatar image
0
Question by Skeelons · Apr 08, 2016 at 10:07 PM · doors

Moving between scenes like an adventure game

Hey, I am new to programming but have been working on a project for a few months now. I am making a 2D game that is supposed to let you move between scenes like in an adventure game. I was using playprefs to store spawn locations for the next scene, but that has recently started becoming very unpredictable.

I have read in many places that I better way to handle this would be to create a singleton object to manage where the character spawns. Could anyone give me any resources that could guide me in how to go about this? I am still very new to all this still and am having a lot of trouble with trying to figure this out.

The script I have bee using is this one, and is attached to trigger objects that are places at both ends of my scene:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.SceneManagement;
 
 public class DoorTrigger2 : MonoBehaviour {
 
     public GameObject MyPlayer;
     public int levelInt;
 
     public float spawnX;
     public float spawnY;
 
 
 
     void OnTriggerEnter2D(Collider2D target)
     {
         if (target.gameObject.tag == "player")
 
             PlayerPrefs.SetFloat ("spawnX", spawnX);
             PlayerPrefs.SetFloat ("spawnY", spawnY);
 
             SceneManager.LoadScene ("level" + levelInt);
 
         
 
     }
 
     void OnLevelWasLoaded ()
     {
         
 
         MyPlayer.transform.position = new Vector3 (PlayerPrefs.GetFloat ("spawnX"), PlayerPrefs.GetFloat ("spawnY"), 0);

//I recently tried to debug to see where the player was trying to spawn, found spawn points to often be far from where I was intending

         Vector3 spawnPt = new Vector3 (PlayerPrefs.GetFloat ("spawnX"), PlayerPrefs.GetFloat ("spawnY"), 0);
         Debug.DrawRay (MyPlayer.transform.position, spawnPt, Color.blue, 1.0f);
         Debug.Log ("Line here");
     }
 
 
 }
 
Comment
Add comment · Show 2
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 cdrandin · Apr 08, 2016 at 10:09 PM 0
Share

This is not an answer, but to help give you insight. Rouge like It is rogue game that when you reach end point a new scene transitions seamlessly with a fader.

Also, well organized and a Unity3D example.

avatar image Skeelons cdrandin · Apr 09, 2016 at 03:45 AM 0
Share

Thanks! I will definitely check this out, it looks like it could help me with what I need!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by $$anonymous$$ · Apr 08, 2016 at 10:35 PM

You can use colliders void OnTriggerEnter(Collider other) { Void OnTrigger Website Unity Scripting API

Or....

If you want to change scenes using keys, like I did, here is a script (JavaScript) for that

 #pragma strict
 
 function Start () {
 
 }
 
 function Update () {
 if(Input.GetKeyDown(KeyCode.Alpha1)){
 Application.LoadLevel("Guy");
 }
 }

Reply back to me if you need more help.

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Door keeps rotating 0 Answers

Door scripting, changing scenes 2 Answers

empty object changes position when add the door object 0 Answers

How can i find the world position of collider? 0 Answers

How do I play an animation from another object C# 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