Hi all, I found this script and its supposed to work… But I’m a Noob at this so i need some serial handholding…
The SpawnPoint is not working and I’m wondering why?
Do I have to delete my Player from the scene he is entering? I read online about “don’t destroy on load” between scenes, but where should I write that? If that’s the case?
This Script Is attached to the Enterance Trigger Box:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LevelLoader : MonoBehaviour
{
private bool playerInZone;
private GUITexture triangleTexture;
public string NextScene;
public string SpawnPointName;
// Use this for initialization
void Start()
{
playerInZone = false;
triangleTexture = GameObject.Find("Triangle").GetComponent<GUITexture>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Joystick1Button3) && playerInZone)//W was original
{
Application.LoadLevel(NextScene);
GetComponent<SpawnAtSpawnPoint>().OnLevelWasLoaded();
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
playerInZone = true;
triangleTexture.enabled = true;
}
}
void OnTriggerExit2D(Collider2D other)
{
if (other.tag == "Player")
{
playerInZone = false;
triangleTexture.enabled = false;
}
}
}
And this script is attacked to the “SpawnPoint Object”
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnAtSpawnPoint : MonoBehaviour
{
GameObject spawnPoint;
public string SpawnPointName;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
public void OnLevelWasLoaded()
{
spawnPoint = GameObject.FindWithTag("SpawnPoint");
if (spawnPoint.name == SpawnPointName)
{
transform.position = spawnPoint.transform.position;
}
}
}