Forum begins after the advertisement:


[Part 6] Player jumping from scenes after start the game

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 6] Player jumping from scenes after start the game

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #19772
    Tú Hoàng Anh
    Level 2
    Participant
    Helpful?
    Up
    0
    ::

    My character just jumping to another scene after i start the game Here is the CameraManger.cs

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Cinemachine;
    public class CameraManager : MonoBehaviour
    {
        [SerializeField] CinemachineVirtualCamera[] virtualCameras;
        private CinemachineVirtualCamera currentCamera;
        private CinemachineFramingTransposer currentTransposer;
        public static CameraManager Instance { get; private set; }
        private void Awake()
        {
            if (Instance == null)
            {
                Instance = this;
            }
            for (int i = 0; i < virtualCameras.Length; i++)
            {
                if (virtualCameras[i].enabled)
                {
                    currentCamera = virtualCameras[i];
                    currentTransposer = currentCamera.GetCinemachineComponent<CinemachineFramingTransposer>();
                }
            }
        }
        private void Start()
        {
            for (int i = 0; i < virtualCameras.Length; i++)
            {
                virtualCameras[i].Follow = PlayerController.Instance.transform;
            }
        }
        public void SwapCamera(CinemachineVirtualCamera _camera)
        {
            currentCamera.enabled = false;
            currentCamera = _camera;
            currentCamera.enabled = true;
        }
    }

    Here is the CameraTrigger.cs

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Cinemachine;
    public class CameraTrigger : MonoBehaviour
    {
        [SerializeField] private CinemachineVirtualCamera newCamera;
        // Start is called before the first frame update
        void Start()
        {
    
        }
        // Update is called once per frame
        void Update()
        {
    
        }
        private void OnTriggerEnter2D(Collider2D _other)
        {
            if(_other.CompareTag("Player"))
            {
                CameraManager.Instance.SwapCamera(newCamera);
            }
        }
    }
    #19774
    Terence
    Level 32
    Keymaster
    Helpful?
    Up
    0
    ::

    What happens when you disable both scripts? Does the issue still happen?

    Try disabling different scripts on the Scene until the issue resolves, then you will know which is the script causing the problem. Once you find that, post the script here again.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: