Topic: Set the character Z-index when they are in Idle

I'd like to know how to identify that a character is in Idle and when it's in Idle set its Z-index in script.

Thank you

Share

Thumbs up Thumbs down

Re: Set the character Z-index when they are in Idle

I threw this together, it should work.

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
    //Attach to your character prefab

    private ControlsScript myControlsScript;

    [SerializeField]
    private int spriteRendererSortingOrder;
         
    private void Start()
    {
        myControlsScript = GetComponentInParent<ControlsScript>();
    }

    private void Update()
    {
        UpdateSpriteRenderer();
    }

    private void UpdateSpriteRenderer()
    {
        if (myControlsScript == null
            || myControlsScript.mySpriteRenderer == null)
        {
            return;
        }

        if (myControlsScript.currentBasicMove == BasicMoveReference.Idle)
        {
            myControlsScript.mySpriteRenderer.sortingOrder = spriteRendererSortingOrder;
        }
    }
}

Share

Thumbs up Thumbs down

Re: Set the character Z-index when they are in Idle

Thank you but where would I set the z-index to 0?

Share

Thumbs up Thumbs down

Re: Set the character Z-index when they are in Idle

By Z-Index do you mean sorting order?
The script has a variable you set in the inspector.

Share

Thumbs up +1 Thumbs down