Having multiple spawn/starting points in one scene
I am new to programming and I am currently trying to make a 2D RPG game in unity. What I am trying to do is have multiple spawn points in one scene. What I am able to do now is go from the starting room to the room with many spawn points, the player spawns at spawn point A when exiting the starting room. The player is then able to go to a different room and when this said player exits that room he finds himself back at spawn point A instead of going to spawn point B (all of those spawn points are in the same room). If whatever I just wrote didn't make any sense, then I have provided a video of the gameplay: https://drive.google.com/file/d/1vykb8016qFsBXcEI65LRx7tB_4Gtb5VO/view?usp=sharing
And here are the scripts that I'm using:
Player Start Point:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerStartPoint : MonoBehaviour
{
private playerController thePlayer;
private camerController theCamera;
public Vector2 startDir;
public string pointName;
// Start is called before the first frame update
void Start()
{
thePlayer = FindObjectOfType<playerController>();
if(thePlayer.startPoint == pointName)
{
thePlayer.transform.position = transform.position;
thePlayer.lastMove = startDir;
theCamera = FindObjectOfType<camerController>();
theCamera.transform.position = new Vector3(transform.position.x, transform.position.y, theCamera.transform.position.z);
}
}
// Update is called once per frame
void Update()
{
}
}
Load New Area:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LoadNewArea : MonoBehaviour
{
void start()
{
thePlayer = FindObjectOfType<playerController>();
}
public string exitPoint;
private playerController thePlayer;
[SerializeField] private string newLevel;
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
SceneManager.LoadScene(newLevel);
thePlayer.startPoint = exitPoint;
}
}
}
Your answer
Follow this Question
Related Questions
Bullets not visible in the game view when I move left 0 Answers
I'm making a 2D game with no levels like flappy bird. How many scenes will I need? 1 Answer
[Question] Unity C# Set a Player Class and refence issue 0 Answers
2D Sprite is floating when I move him (Rigidbody2D) 0 Answers
How do I make a hand drawn map effect of a 2d game scene like this! 0 Answers