Forum begins after the advertisement:
[Part 10] SceneTransition Minor Bug
Home › Forums › Video Game Tutorial Series › Creating a Farming RPG in Unity › [Part 10] SceneTransition Minor Bug
- This topic has 5 replies, 4 voices, and was last updated 3 days, 15 hours ago by Tarha Apustaja.
-
AuthorPosts
-
December 14, 2024 at 10:33 pm #16778::
I have a Minor Bug after following the Part 10, like when the player comes from the city, it always transform it self to the Transform from the Bedroom (FromHouse on tutorial), see attached Images and Video
View post on imgur.com
December 14, 2024 at 10:35 pm #16779::This is the script relating to Part 10
LocationEntryPoint
using System.Collections; using System.Collections.Generic; using UnityEngine; public class LocationEntryPoint : MonoBehaviour { [SerializeField] SceneTransitionManager.Location locationToSwitch; private void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { SceneTransitionManager.Instance.SwitchLocation(locationToSwitch); } } }
Location Manager
using System.Collections; using System.Collections.Generic; using UnityEngine; public class LocationManager : MonoBehaviour { public static LocationManager Instance { get; private set; } public List<StartPoint> startPoints; public void Awake() { if(Instance != null && Instance != this) { Destroy(this); } else { Instance = this; } } public Transform GetPlayerStartingPosition(SceneTransitionManager.Location enteringFrom) { StartPoint startingPoint = startPoints.Find(x => x.enteringFrom == enteringFrom); return startingPoint.playerStart; } }
SceneTransition Manager
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class SceneTransitionManager : MonoBehaviour { public static SceneTransitionManager Instance; public enum Location { Bedroom, PlantingArea, TestCity} public Location currentLocation; Transform playerPoint; private void Awake() { if (Instance != null && Instance != this) { Destroy(gameObject); } else { Instance = this; } DontDestroyOnLoad(gameObject); SceneManager.sceneLoaded += OnLocationLoad; playerPoint = FindObjectOfType<PlayerMove>().transform; } //Switch the player to another scene public void SwitchLocation(Location locationToSwitch) { SceneManager.LoadScene(locationToSwitch.ToString()); } //Called when a scene is loaded public void OnLocationLoad(Scene scene, LoadSceneMode mode) { //The location the player is coming from when the scene loads Location oldLocation = currentLocation; //Get the new location by converting the string of our current scene into a Location enum value Location newLocation = (Location)Enum.Parse(typeof(Location), scene.name); //If the player is not coming from any new place, stop executing function if (currentLocation == newLocation) return; //Find the start point Transform startPoint = LocationManager.Instance.GetPlayerStartingPosition(oldLocation); //Disable the player's CharacterController component CharacterController playerCharacter = playerPoint.GetComponent<CharacterController>(); playerCharacter.enabled = false; //Change the player's position to the start point playerPoint.position = startPoint.position; playerPoint.rotation = startPoint.rotation; //Re-enable player character controller so player can move playerCharacter.enabled = true; //Save the current location that we just switched to currentLocation = newLocation; } }
StartPoint
using System.Collections; using System.Collections.Generic; using UnityEngine; [System.Serializable] public struct StartPoint { public SceneTransitionManager.Location enteringFrom; public Transform playerStart; }
Basically the same scripts
December 15, 2024 at 4:17 am #16780::It seems like you have shared scripts related to scene transitioning and location management in Unity. If you have any specific questions or issues regarding these scripts, feel free to ask!
December 15, 2024 at 10:33 am #16781::So please provide advice Mr. Apustaja. The poster already said that he has a Minor Bug after following the Part 10. When the player comes from the city, he always uses the position in from the Bedroom.
December 15, 2024 at 12:17 pm #16782::Hello, User 1! Thank you for reaching out to me for advice. It sounds like the player’s position is not being correctly updated when transitioning from the city to the bedroom.
One common reason for this issue could be related to how the player’s position is being saved or loaded during the transition. Make sure that the player’s position is being properly updated and saved when leaving the city and loaded correctly when entering the bedroom.
Additionally, check for any code that might be overriding the player’s position when transitioning between these two locations. It’s important to ensure that the player’s position is being handled consistently throughout the game to avoid
December 15, 2024 at 1:37 pm #16783December 15, 2024 at 1:40 pm #16784December 15, 2024 at 3:08 pm #16785December 15, 2024 at 7:17 pm #16791::Hey there, A_DONUT! How can I assist you today? If you have any programming questions or need help with anything tech-related, feel free to ask!
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: