Forum begins after the advertisement:


Search Results for 'fader'

Home Forums Search Search Results for 'fader'

Viewing 15 results - 1 through 15 (of 84 total)
  • Author
    Search Results
  • A_DONUT
    Moderator

    Let’s go through each of your issues step-by-step:


    1. Console Error in UIManager:

    The error might be related to how DontDestroyOnLoad() is interacting with other scripts or objects. Ensure the sceneFader component is properly linked, and double-check if your UIManager object exists in the scene hierarchy.

    Potential fixes:

    • Ensure that SceneFader is attached as a child object in the inspector.
    • Check for duplicate UIManager objects when the scene reloads.
    • Add Debug.Log to verify the sceneFader assignment.

    2. Bat Stun Issue:

    Problem: The bat gets stunned even if stunDuration is set to 0 and also gets stunned/knockbacked after dying.

    Fixes:

    • Check stun logic:
      In EnemyHit(), ensure the bat only gets stunned if the stunDuration is greater than zero:

      csharp
      if (health > 0 && stunDuration > 0)
      {
          ChangeState(EnemyStates.Bat_Stunned);
      }
      else if (health <= 0)
      {
          ChangeState(EnemyStates.Bat_Death);
      }
      <code></code>
    • Disable collision after death:
      In Death(), ensure that the bat no longer processes hit logic or collisions:

      csharp
      protected override void Death(float destroyTime)
      {
          base.Death(destroyTime);
          rb.velocity = Vector2.zero; // Stop all movement
          rb.gravityScale = 12;
          GetComponent<Collider2D>().enabled = false; // Disable collisions
      }
      <code></code>

    3. Jumping Too High:

    Problem: The character sometimes jumps too high when you lightly tap the jump button.

    Fix: Adjust the Jump() method to apply a minimum height and reduce velocity more smoothly:

    csharp
    if (Input.GetButtonUp("Jump") && rb.velocity.y > 3)
    {
        rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f); // Reduce, but don't cancel instantly
    }
    <code></code>

    Also, ensure jumpBufferCounter and coyoteTimeCounter are reset correctly after jumps.


    4. Walljumping Issue (Directional Problems):

    Problem: Walljumping works only on the right-side wall correctly.

    Fix: Ensure the walljump direction logic is symmetrical:

    csharp
    if (Input.GetButtonDown("Jump") && isWallSliding)
    {
        isWallJumping = true;
        float jumpDirection = pState.lookingRight ? -1 : 1; // Simplified for clarity
        rb.velocity = new Vector2(jumpDirection * wallJumpingPower.x, wallJumpingPower.y);
        Invoke(nameof(StopWallJumping), wallJumpingDuration);
    }
    <code></code>

    Also, remove any unnecessary transform.eulerAngles adjustments unless flipping visually.


    5. Camera Reset After Scene Transition:

    Problem: Returning to a previous scene doesn’t set the correct camera position.

    Fix: Store the current camera or position before transitioning:

    csharp
    public Vector3 lastCameraPosition;
    
    // Before transitioning scenes
    lastCameraPosition = Camera.main.transform.position;
    
    // After loading the scene, reset the camera
    Camera.main.transform.position = lastCameraPosition;
    <code></code>

    6. Unpause Game with Escape Key:

    Add an Escape key check in your Update() function:

    csharp
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (gameIsPause)
            {
                unpauseGame(); // Unpause the game if it's already paused
            }
            else
            {
                // Existing code to pause the game
                pauseMenu.fadeUIIn(fadeTime);
                Time.timeScale = 0;
                gameIsPause = true;
            }
        }
    }
    <code></code>

    These changes should address your issues. Let me know if you need further clarification or have more details to share! 😊

    Terence
    Keymaster

    Can you show me your UIManager, SceneTransition and SceneFader scripts?

    Terence
    Keymaster

    Try adding this line to SceneTransition. That should fix it:

        private void OnTriggerEnter2D(Collider2D _other)
        {
            if (_other.CompareTag("Player"))
            {
                GameManager.Instance.transitionedFromScene = SceneManager.GetActiveScene().name;
    
                PlayerController.Instance.pState.cutscene = true;
                PlayerController.Instance.pState.invincible = true;
                if(UIManager.Instance.sceneFader == null)
                    UIManager.Instance.sceneFader = UIManager.Instance.GetComponentInChildren<SceneFader>();
                StartCoroutine(UIManager.Instance.sceneFader.FadeAndLoadScene(SceneFader.FadeDirection.In, transitionTo));
            }
        }

    The problem is likely that UIManager loads after SceneTransition, causing UIManager.Instance.sceneFader to be null and breaking the sceneFader transition.

    tai
    Former Patron

    Here is the SceneFader.cs. It already changed to Awake when i downloaded it.

    <code>using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    using UnityEngine.SceneManagement;
    
    public class SceneFader : MonoBehaviour
    {
        public float fadeTime;
    
        private Image fadeOutUIImage;
    
        public enum FadeDirection
        {
            In, 
            Out
        }
    
        // Start is called before the first frame update
        void Awake()
        {
            fadeOutUIImage = GetComponent<Image>();
        }
    
        // Update is called once per frame
        void Update()
        {
    
        }
    
        public void CallFadeAndLoadScene(string _sceneToLoad)
        {
            StartCoroutine(FadeAndLoadScene(FadeDirection.In, _sceneToLoad));
        }
    
        public IEnumerator Fade(FadeDirection _fadeDirection)
        {
            float _alpha = _fadeDirection == FadeDirection.Out ? 1 : 0;
            float _fadeEndValue = _fadeDirection == FadeDirection.Out ? 0 : 1;
    
            if(_fadeDirection == FadeDirection.Out)
            {
                while(_alpha >= _fadeEndValue)
                {
                    SetColorImage(ref _alpha, _fadeDirection);
    
                    yield return null;
                }
    
                fadeOutUIImage.enabled = false;
            }
            else
            {
                fadeOutUIImage.enabled = true;
    
                while (_alpha <= _fadeEndValue)
                {
                    SetColorImage(ref _alpha, _fadeDirection);
    
                    yield return null;
                }
            }
        }
    
        public IEnumerator FadeAndLoadScene(FadeDirection _fadeDirection, string _sceneToLoad)
        {
            fadeOutUIImage.enabled = true;
    
            yield return Fade(_fadeDirection);
    
            SceneManager.LoadScene(_sceneToLoad);
        }
    
        void SetColorImage(ref float _alpha, FadeDirection _fadeDirection)
        {
            fadeOutUIImage.color = new Color(fadeOutUIImage.color.r, fadeOutUIImage.color.g, fadeOutUIImage.color.b, _alpha);
    
            _alpha += 0.02f * (_fadeDirection == FadeDirection.Out ? -1 : 1);
        }
    }
    </code>
    Terence
    Keymaster

    If you are still working on the 9.5 files, try changing the Start() to Awake() in SceneFader and see if it fixes the issue. More information here: https://blog.terresquall.com/community/topic/part-5-article-changes-common-issues-bugfixes/

    Terence
    Keymaster

    That is strange. Try expanding the Cave_1 file in your Scene after loading the new level:

    View post on imgur.com

    I suspect the Scene is loading, but the Scene Fader isn’t deactivating so it looks like the scene isn’t loading.

    tai
    Former Patron

    Hi, i am trying out the Part 9.5 project files the project worked fine but all the ability is unlock so i delete all the save files in the folder C:\Users\phamh\AppData\LocalLow\DefaultCompany\Metroidvania Tutorial.

    View post on imgur.com

    When i reload the project and open from Main Menu scene its normal but when i clicked Play the screen turned black and i can only hear sound in the background as in the video.

    I have tried redownload the project files but its not working anymore.

    #16280
    Ferral Child
    Participant

    Okay, I screen recorded and it captured something I didn’t notice is that the UI Manager, Canvas, and Scene Fader disappear when I play the game.

    View post on imgur.com

    Thank you for being so patient with me ;<;

    #16277
    Chloe Lim
    Moderator

    Ok, could you record a video of the scenefader game object inspector during play? Just play the scene and select the scenefader in the hierarchy

    has upvoted this post.
    #16273
    Chloe Lim
    Moderator

    Ok, in your recording it seems that your scenetransition script is failing to start the coroutine of the scene fading in the at start, which means that the UIManager is unable to find the scenefader to start the fade sequence, is the scenefader game object assigned in the inspector of your UIManager Script?

    #16272
    Ferral Child
    Participant

    I checked- Scene Transition, Start Point, UI Manager, Canvas, and Scene Fader are all enabled.

    #16268
    Chloe Lim
    Moderator

    Ok, is your scenefader ui disabled in the hiearchy? need to enable it or there will be a null exception as the script cant find the inactive scenefader When your scene starts, there should be a fade out, then when moving to another scene it will fade in then out again to the new scene

    has upvoted this post.
    #16264
    Ferral Child
    Participant

    Hello,

    I am having issues with getting my scene transition to work. As no matter how many times I run into what should be the transition ‘doorway’ to the next scene, nothing happens at all. Any advice would be greatly appreciated!

    Code Below:

    Player Controller

    <code>using System.Collections;
    using System.Collections.Generic;
    
    using UnityEngine;
    
    public class playerController : MonoBehaviour
    {
    
        [SerializeField] private float walkspeed = 1;
    
        [SerializeField] private float JumpForce = 45;
        private int JumpBufferCounter = 0;
        [SerializeField] private int JumpBufferFrames;
        private float CoyoteTimeCounter = 0;
        [SerializeField] private float CoyoteTime;
        private int AirJumpCounter = 0;
        [SerializeField] private int maxAirJumps;
    
        //Ground Check Settings
    
        [SerializeField] private Transform GroundCheckPoint;
        [SerializeField] private float GroundCheckY = 0.2f;
        [SerializeField] private float GroundCheckX = 0.5f;
        [SerializeField] private LayerMask WhatIsGround;
    
        //Dash Settings
    
        [SerializeField] private float dashSpeed;
        [SerializeField] private float dashTime;
        [SerializeField] private float dashCooldown;
    
        //Attack Settings
    
        [SerializeField] private Transform SideAttackTransform, UpAttackTransform, DownAttackTransform;
        [SerializeField] private Vector2 SideAttackArea, UpAttackArea, DownAttackArea;
        [SerializeField] private LayerMask AttackableLayer;
        [SerializeField] private float timeBetweenAttack;
        [SerializeField] private float damage;
    
        private int stepsXRecoiled, stepsYRecoiled;
    
        // Recoil Settings
    
        [SerializeField] private int recoilXSteps = 5; 
        [SerializeField] private int recoilYSteps = 5; 
        [SerializeField] private float recoilXSpeed = 100;
        [SerializeField] private float recoilYSpeed = 100;
    
        //Health Settings
    
        public int health;
       public int maxHealth;
        [SerializeField] GameObject DamagePart;
        [SerializeField] float hitFlashSpeed;
    
        [HideInInspector] public PlayerStateList pState;
        public Rigidbody2D rb;
        private Animator anim;
        private SpriteRenderer sr;
    
        private float xAxis, yAxis;
        private float gravity;
        private bool canDash = true;
        private bool dashed;
    
        private bool attack = false;
        private float timeSinceAttack;
    
        bool restoreTime;
        float restoreTimeSpeed;
    
        public static playerController Instance;
    
    
        private void Awake()
        {
            if (Instance != null && Instance != this)
            {
                Destroy(gameObject);
            }
            else
            {
                Instance = this;
            }
            Health = maxHealth;
        }
    
        // Start is called before the first frame update
        void Start()
        {
            pState = GetComponent<PlayerStateList>();
            rb = GetComponent<Rigidbody2D>();
            anim = GetComponent<Animator>();
            gravity = rb.gravityScale;
            sr = GetComponent<SpriteRenderer>();
        }
    
        private void OnDrawGizmos()
        {
            Gizmos.color = Color.red;
            Gizmos.DrawWireCube(SideAttackTransform.position, SideAttackArea);
            Gizmos.DrawWireCube(UpAttackTransform.position, UpAttackArea);
            Gizmos.DrawWireCube(DownAttackTransform.position, DownAttackArea);
        }
    
        // Update is called once per frame
        void Update()
        {
            if (pState.cutscene) return;
            GetInputs();
            RestoreTimeScale();
            UpdateJumpVariables();
            if (pState.Dashing) return;
            Flip();
            Move();
            Jump();
            StartDash();
            Attack();
            Recoil();
            FlashWhileInvincible();
        }
    
        private void FixedUpdate()
        {
            if (pState.Dashing || pState.cutscene) return;
            Recoil();
        }
    
        void GetInputs()
        {
            xAxis = Input.GetAxisRaw("Horizontal");
            yAxis = Input.GetAxisRaw("Vertical");
            attack = Input.GetButtonDown("attack");
        }
    
        void Flip()
        {
            if (xAxis < 0)
            {
                transform.localScale = new
                Vector2(-Mathf.Abs(transform.localScale.x), transform.localScale.y);
                pState.lookingRight = false;
            }
            else if (xAxis > 0)
            {
                transform.localScale = new
                    Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
                    pState.lookingRight = true;
            }
        }
    
        private void Move()
        {
            rb.velocity = new Vector2(walkspeed * xAxis, rb.velocity.y);
            anim.SetBool("Walking", rb.velocity.x != 0 && Grounded());
        }
    
        void StartDash()
        {
            if (Input.GetButtonDown("Dash") && canDash && !dashed)
            {
                StartCoroutine(Dash());
                dashed = true;
            }
            if (Grounded())
            {
                dashed = false;
            }
        }
    
        IEnumerator Dash()
        {
            canDash = false;
            pState.Dashing = true;
            anim.SetTrigger("Dashing");
            rb.gravityScale = 0;
            rb.velocity = new Vector2(transform.localScale.x * dashSpeed, 0);
            yield return new WaitForSeconds(dashTime);
            rb.gravityScale = gravity;
            pState.Dashing = false;
            yield return new WaitForSeconds(dashCooldown);
            canDash = true;
        }
    
        public IEnumerator WalkIntoNewScene(Vector2 _exitDir, float _delay)
        {
            pState.invincible = true;
    
            //If exit direction is upwards
            if (_exitDir.y > 0)
            {
                rb.velocity = JumpForce * _exitDir;
            }
    
            //If exit direction requires horizontal movement
            if (_exitDir.x != 0)
            {
                xAxis = _exitDir.x > 0 ? 1 : -1;
                Move();
            }
    
            Flip();
            yield return new WaitForSeconds(_delay);
            pState.invincible = false;
            pState.cutscene = false;
        }
    
        void Attack()
        {
            timeSinceAttack += Time.deltaTime;
            if(attack && timeSinceAttack >= timeBetweenAttack) 
            {
                timeSinceAttack = 0;
                anim.SetTrigger("Attacking");
    
                if(yAxis == 0 || yAxis < 0 && Grounded ())
                {
                    int _recoilLeftorRight = pState.lookingRight ? 1 : -1;
    
                    Hit(SideAttackTransform, SideAttackArea, ref pState.recoilingX, Vector2.right * _recoilLeftorRight, recoilXSpeed);
                }
                else if(yAxis > 0)
                {
                    Hit(UpAttackTransform, UpAttackArea, ref pState.recoilingY, Vector2.up, recoilYSpeed);
                }
                else if (yAxis < 0 && !Grounded())
                {
                    Hit(DownAttackTransform, DownAttackArea, ref pState.recoilingY, Vector2.down, recoilYSpeed);
                }
            }
        }
    
         void Hit(Transform _attackTransform, Vector2 _attackArea, ref bool _recoilBool, Vector2 _recoilDir, float _recoilStrength)
        {
            Collider2D[] objectsToHit = Physics2D.OverlapBoxAll(_attackTransform.position, _attackArea, 0, AttackableLayer);
    
            List<Enemy> hitEnemies = new List<Enemy>();
    
            if (objectsToHit.Length > 0)
            {
                _recoilBool = true;
            }
    
    
            for (int i = 0; i < objectsToHit.Length; i++)
            {
                Debug.Log("Hit");
                Enemy e = objectsToHit[i].GetComponent<Enemy>();
    
                if (objectsToHit[i].GetComponent<Enemy>() != null)
                {
                    objectsToHit[i].GetComponent<Enemy>().EnemyHit(damage, _recoilDir, _recoilStrength);
                }
            }
        }
    
        void Recoil()
        {
            if (pState.recoilingX)
            {
                if (pState.lookingRight)
                {
                    rb.velocity = new Vector2(-recoilXSpeed, 0);
                }
                else
                {
                    rb.velocity = new Vector2(recoilXSpeed, 0);
                }
            }
    
            if (pState.recoilingY)
            {
                rb.gravityScale = 0;
                if (yAxis < 0)
                {
                    rb.velocity = new Vector2(rb.velocity.x, recoilYSpeed);
                }
                else
                {
                    rb.velocity = new Vector2(rb.velocity.x, -recoilYSpeed);
                }
                AirJumpCounter = 0;
            }
            else
            {
                rb.gravityScale = gravity;
            }
            //stop recoil
            if (pState.recoilingX && stepsXRecoiled < recoilXSteps)
            {
                stepsXRecoiled++;
            }
            else
            {
                StopRecoilX();
            }
            if (pState.recoilingY && stepsYRecoiled < recoilYSteps)
            {
                stepsYRecoiled++;
            }
            else
            {
                StopRecoilY();
            }
    
            if (Grounded())
            {
                StopRecoilY();
            }
        }
        void StopRecoilX()
        {
            stepsXRecoiled = 0;
            pState.recoilingX = false;
        }
        void StopRecoilY()
        {
            stepsYRecoiled = 0;
            pState.recoilingY = false;
        }
    
        public void TakeDamage(float _damage)
        {
            Health -= Mathf.RoundToInt(_damage);
            StartCoroutine(StopTakingDamage());
        }
    
        IEnumerator StopTakingDamage()
        {
            pState.invincible = true;
            GameObject _DamagePartParticles = Instantiate(DamagePart, transform.position, Quaternion.identity);
            Destroy(_DamagePartParticles, 1.5f);
            anim.SetTrigger("TakeDamage");
            yield return new WaitForSeconds(1f);
            pState.invincible = false;
        }
    
        void FlashWhileInvincible()
        {
            if (pState.cutscene) return;
            sr.material.color = pState.invincible ? Color.Lerp(Color.white, Color.black, Mathf.PingPong(Time.time * hitFlashSpeed, 1.0f)) : Color.white;
        }
    
        void RestoreTimeScale()
        {
            if (restoreTime)
            {
                if (Time.timeScale < 1)
                {
                    Time.timeScale += Time.unscaledDeltaTime * restoreTimeSpeed;
                }
                else
                {
                    Time.timeScale = 1;
                    restoreTime = false;
                }
            }
        }
    
        public void HitStopTime(float _newTimeScale, int _restoreSpeed, float _delay)
        {
            restoreTimeSpeed = _restoreSpeed;
    
            if (_delay > 0)
            {
                StopCoroutine(StartTimeAgain(_delay));
                StartCoroutine(StartTimeAgain(_delay));
            }
            else
            {
                restoreTime = true;
            }
    
            Time.timeScale = _newTimeScale;
        }
    
        IEnumerator StartTimeAgain(float _delay)
        {
            yield return new WaitForSecondsRealtime(_delay);
            restoreTime = true;
        }
    
        public int Health
        {
            get { return health; }
            set
            {
                if (health != value)
                {
                    health = Mathf.Clamp(value, 0, maxHealth);
                }
            }
        }
    
        public bool Grounded()
        {
            if (Physics2D.Raycast(GroundCheckPoint.position, Vector2.down, GroundCheckY, WhatIsGround)
                || Physics2D.Raycast(GroundCheckPoint.position + new Vector3(GroundCheckX, 0, 0), Vector2.down, GroundCheckY, WhatIsGround)
                || Physics2D.Raycast(GroundCheckPoint.position + new Vector3(-GroundCheckX, 0, 0), Vector2.down, GroundCheckY, WhatIsGround))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    
        void Jump()
        {
            if(Input.GetButtonUp("Jump") && rb.velocity.y > 0)
                {
                rb.velocity = new Vector2(rb.velocity.x, 0);
    
                pState.jumping = false; 
            }
    
            anim.SetBool("Jumping", !Grounded());
    
            if (!pState.jumping)
            {
    
                if (JumpBufferCounter >0 && CoyoteTimeCounter > 0)
                {
                    rb.velocity = new Vector3(rb.velocity.x, JumpForce);
    
                    pState.jumping = true;
                }
                else if(!Grounded() && AirJumpCounter < maxAirJumps && Input.GetButtonDown("Jump"))
                {
                    pState.jumping = true;
    
                    AirJumpCounter++;
    
                    rb.velocity = new Vector3(rb.velocity.x, JumpForce);
    
    
                }
            }
        }
        void UpdateJumpVariables()
        {
            if (Grounded())
            {
                pState.jumping = false;
                CoyoteTimeCounter = CoyoteTime;
                AirJumpCounter = 0;
            }
            else 
            {
                CoyoteTimeCounter -= Time.deltaTime;
            }
            if (Input.GetButtonDown("Jump"))
            {
                JumpBufferCounter = JumpBufferFrames;
            }
            else
            {
                JumpBufferCounter--;
            }
        }
    }</code>

    Game Manager:

    <code>using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class GameManager : MonoBehaviour
    {
        public string transitionedFromScene;
    
        public Vector2 platformingRespawnPoint;
    
        public static GameManager Instance {get; private set;}
    
        private void Awake()
        {
            if(Instance != null && Instance != this)
            {
                Destroy(gameObject);
            }
            else
            {
                Instance = this;
            }
            DontDestroyOnLoad(gameObject);
        }
    
    }
    </code>

    Scene Fader

    <code>using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    using UnityEngine.SceneManagement;
    
    public class SceneFader : MonoBehaviour
    {
        [SerializeField] public float fadeTime;
    
        private Image fadeOutUIImage;
        public enum FadeDirection
        {
            In,
            Out
        }
    
        private void Awake()
        {
            fadeOutUIImage = GetComponent<Image>();
        }
    
        public IEnumerator Fade(FadeDirection _fadeDirection)
        {
            float _alpha = _fadeDirection == FadeDirection.Out ? 1 : 0;
            float _fadeEndValue = _fadeDirection == FadeDirection.Out ? 0 : 1;
    
            if (_fadeDirection == FadeDirection.Out)
            {
                while (_alpha >= _fadeEndValue)
                {
                    SetColorImage(ref _alpha, _fadeDirection);
    
                    yield return null;
                }
    
                fadeOutUIImage.enabled = false;
            }
            else
            {
                fadeOutUIImage.enabled = true;
    
                while (_alpha <= _fadeEndValue)
                {
                    SetColorImage(ref _alpha, _fadeDirection);
    
                    yield return null;
                }
            }
        }
        public IEnumerator FadeAndLoadScene(FadeDirection _fadeDirection, string _sceneToLoad)
        {
            fadeOutUIImage.enabled = true;
    
            yield return Fade(_fadeDirection);
    
            SceneManager.LoadScene(_sceneToLoad);
        }
    
        void SetColorImage(ref float _alpha, FadeDirection _fadeDirection)
        {
            fadeOutUIImage.color = new Color(fadeOutUIImage.color.r, fadeOutUIImage.color.g, fadeOutUIImage.color.b, _alpha);
    
            _alpha += Time.deltaTime * (1 / fadeTime) * (_fadeDirection == FadeDirection.Out ? -1 : 1);
        }
    }
    </code>

    Scene Transition:

    <code>
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    
    public class SceneTransition : MonoBehaviour
    {
        [SerializeField] private string transitionTo;
    
        [SerializeField] private Transform startPoint;
    
        [SerializeField] private Vector2 exitDirection;
    
        [SerializeField] private float exitTime;
    
        private void Start()
        {
            if (GameManager.Instance.transitionedFromScene == transitionTo)
            {
                playerController.Instance.transform.position = startPoint.position;
    
                StartCoroutine(playerController.Instance.WalkIntoNewScene(exitDirection, exitTime));
            }
            StartCoroutine(UIManager.Instance.sceneFader.Fade(SceneFader.FadeDirection.Out));
        }
    
        private void OnTriggerEnter2D(Collider2D _other)
        {
            if (_other.CompareTag("Player"))
            {
                GameManager.Instance.transitionedFromScene = SceneManager.GetActiveScene().name;
    
                playerController.Instance.pState.cutscene = true;
                playerController.Instance.pState.invincible = true;
    
                StartCoroutine(UIManager.Instance.sceneFader.FadeAndLoadScene(SceneFader.FadeDirection.In, transitionTo));
            }
        }
    }
    </code>

    UI Manager

    <code>using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class UIManager : MonoBehaviour
    {
        public SceneFader sceneFader;
    
        public static UIManager Instance;
    
        private void Awake()
        {
            if (Instance != null && Instance != this)
            {
                Destroy(gameObject);
            }
            else
            {
                Instance = this;
            }
            DontDestroyOnLoad(gameObject);
    
            sceneFader = GetComponentInChildren<SceneFader>();
        }
    }
    </code>
    #16210
    Chloe Lim
    Moderator

    Try to add rb.constraints = RigidbodyContraints2D.FreezePosition to your player death function for the gameover screen, ensure that the gameove text and button is below in the hiearchy of the scene fader, like this

    pepecry
    Participant

    Hi everyone, I’m on the way to make the scene fading but got some trouble with it now. Firstly when I start the game, the image not was render under the game build like the video. Don’t know that does I miss anything in the video. Here is the scene fader of my

    Scene fading in canvas and here is the Inspector of it Inspector If i turn off the image and start the game, there is some error happend in the console Console log the first two error happand with start of the game. The third error happend when I get to the scene transition point. My character keep moving and the error happend. Here is the scene transition code
    <code>using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    
    public class SceneTransition : MonoBehaviour
    {
        // Start is called before the first frame update
    
        [SerializeField] private string transitionTo;
        [SerializeField] private Transform startPoint;
        [SerializeField] private Vector2 directionExit;
        [SerializeField] private float exitTime;
    
        private void Start()
        {
            if (transitionTo == GameManager.Instance.transitionFromScene)
            {
                Move.Instance.transform.position = startPoint.position;
                StartCoroutine(Move.Instance.WalktonewScene(directionExit,exitTime));
            }
    
            StartCoroutine(UIManager.Instance.sceneFading.Fade(SceneFading.fadeDirection.Out));
    
        }
        private void OnTriggerEnter2D(Collider2D _other)
        {
            if (_other.CompareTag("Player"))
            {
                GameManager.Instance.transitionFromScene = SceneManager.GetActiveScene().name;
                Move.Instance.playerStateList.incutscene = true;
                StartCoroutine(UIManager.Instance.sceneFading.FadeAndLoadScene(SceneFading.fadeDirection.In,transitionTo));
            }
        }
    }
    </code>

    the scenefading script

    <code>using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    using UnityEngine.SceneManagement;
    
    public class SceneFading : MonoBehaviour
    {
    
        [SerializeField] private float fadeTime;
        private Image fadeoutUIImage;
        public enum fadeDirection
        {
            In,
            Out
        }
        // Start is called before the first frame update
        void Awake()
        {
            fadeoutUIImage = GetComponent<Image>();
        }
    
        // Update is called once per frame
        void Update()
        {
    
        }
    
        public IEnumerator Fade(fadeDirection _fadeDirection)
        {
            float _alpha = _fadeDirection == fadeDirection.Out ? 1 : 0;
            float _fadeEndValue = _fadeDirection == fadeDirection.Out ? 0 : 1;
    
            if (_fadeDirection == fadeDirection.Out) 
            {
                while (_alpha >= _fadeEndValue) 
                {
                    setColorImage(ref _alpha,_fadeDirection);
                    yield return null;
                }
                fadeoutUIImage.enabled = false;
            }
            else
            {
                fadeoutUIImage.enabled = true;
                while(_alpha <= _fadeEndValue)
                {
                    setColorImage(ref _alpha,_fadeDirection);
                    yield return null;
                }
            }
    
        }
    
        public IEnumerator FadeAndLoadScene(fadeDirection _fadeDirection, string _sceneToLoad)
        {
            fadeoutUIImage.enabled = true ;
            yield return Fade(_fadeDirection);
            SceneManager.LoadScene(_sceneToLoad);
        }
    
        void setColorImage(ref float _alpha, fadeDirection _fadeDirection)
        {
            fadeoutUIImage.color = new Color(fadeoutUIImage.color.r, fadeoutUIImage.color.g, fadeoutUIImage.color.b, _alpha);
            _alpha += Time.deltaTime * (1/fadeTime) * (_fadeDirection == fadeDirection.Out ? -1 : 1);
        }
    }
    </code>

    I already change the start from scene fading to the Awake but still cannot fix the null refference. Can you guys help me to make the black image render behind the game and fix this bug?

Viewing 15 results - 1 through 15 (of 84 total)

Advertisement below: