How do I code my player to spin and shrink on colliding with the exit?

I’m on the TileVania course and I wanted to code in when the player collides with the exit it could spin and appear to shrink into the exit sprite. Not sure where I would start on this one. How would I code this?

This is my current LevelExit sprite script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class LevelExit : MonoBehaviour
{
[SerializeField] float LevelLoadDelay = 2f;

void OnTriggerEnter2D(Collider2D other)
{
    StartCoroutine(LoadNextLevel());
}

IEnumerator LoadNextLevel()
{
    yield return new WaitForSecondsRealtime(LevelLoadDelay);
    
    var currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
    SceneManager.LoadScene(currentSceneIndex + 1);
}

}

Hi Josh,

The trick is to break the problem/solution down into single tasks.

  1. Log a message into your console when the player collides with something.
  2. Log a message into your console when the player collides with the exit collider.
  3. Create a new animation state for the exiting animation, and create your animation. Add a bool or a trigger to the state.
  4. Set the bool/trigger to true when the player collides with the exit collider.
  5. Load the next scene when the animation is done. This could be achieved with an animation event.

Hopefully, this helped. :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms