Advertisement
LeeMace

Keep Player & Info into new Level

Mar 16th, 2023 (edited)
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | Gaming | 0 0
  1. //In Player Script
  2. //keeping original player from previous level and destroying new instance
  3.     private void Awake()
  4.     {
  5.         if (instance == null)
  6.         {
  7.             instance = this;
  8.         }
  9.         else
  10.         {
  11.             Destroy(gameObject);
  12.         }
  13.     }
  14.  
  15.     void Start()
  16.     {
  17.         //This keeps the player to port over to the new level
  18.         DontDestroyOnLoad(gameObject);
  19.     }
  20.  
  21. //get virtual camera to follow the player in the new level
  22. using Cinemachine;
  23. using System.Collections;
  24. using System.Collections.Generic;
  25. using UnityEngine;
  26.  
  27. public class SceneCamera : MonoBehaviour
  28. {
  29.     [SerializeField] private CinemachineVirtualCamera cinemachineVirtualCamera;
  30.    
  31.     void Start()
  32.     {
  33.         //get the camera to follow the player in the new level
  34.         cinemachineVirtualCamera.Follow = NewPlayer.Instance.transform;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement