Quantcast
Channel: Questions in topic: "clone"
Viewing all articles
Browse latest Browse all 508

Prevent more then one player clone in a scene

$
0
0
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(); } } 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); } }

Viewing all articles
Browse latest Browse all 508


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>