- Home /
Question by
samccloy4 · Jul 20, 2021 at 09:44 PM ·
instantiateclonerespawn
Prevent more then one player clone in a scene
My Player is cloning at run time occasionally and when I switch scenes it duplicates im using. a game manager to instantiate when respawn is called also im using easysave3.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Game_Master : MonoBehaviour
{
public static Game_Master gm;
public Vector2 lastCheckPointPos;
private static Game_Master instance;
Scene scene;
public GameObject player;
void Awake(){
Debug.Log("Awake;" + SceneManager.GetActiveScene().name);
if(instance == null){
instance = this;
DontDestroyOnLoad(instance);
}else {
Destroy(gameObject);
}
}
void Start () {
if (gm == null) {
gm = GameObject.FindGameObjectWithTag ("GM").GetComponent<Game_Master>();
}
}
public Transform playerPrefab;
public Transform spawnPoint;
public int spawnDelay = 2;
public IEnumerator _RespawnPlayer ()
{
Debug.Log ("TODO: Add waiting for spawn sound");
yield return new WaitForSeconds (spawnDelay);
Instantiate (playerPrefab, spawnPoint.position, spawnPoint.rotation);
Debug.Log ("TODO: Add Spawn Particles");
}
public static void KillPlayer (Player player) {
Destroy (player.gameObject);
gm.StartCoroutine (gm._RespawnPlayer());
}
public static void KillEnemy (Enemy enemy) {
Destroy (enemy.gameObject);
}
}
Comment
Your answer

Follow this Question
Related Questions
Deep clone a gameobject 2 Answers
Instantiate creating infinite clones 0 Answers
How can I assign a clone with a script to a variable? without drag & drop 1 Answer
my object instantiates to much 1 Answer
Moving a transform behaves odd 0 Answers