How to Change Text Position on an Actived Button

Here we want to create a UI button effect that the button is lower a few pixels when being clicked to make it feel like being really ‘click down’.


It can be easily done though custom GUIskin. All I need to do is just to assigne two button pics for Normal and Active states in a custom style.


The problem is the text of the button is wrote by script. So far I can only darker the text color when clicking, but can’t change the position/padding of the text, which goes to a really awful effect.


The quickest way to solve it is of course to write the text into the button picture. However we want this game to have muli-language versions. And according to our experience, changing all the pictures for buttons/labels with text can be really frustrated and ineffeciency. Thus the text must be wrote though script. Is there any other solutions for this? Maybe Unity should open more UI events for us to handle more on the appearance of UI controllers in different states

The following script is attached to an empty gameObject:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DisplacePressedButtonText : MonoBehaviour
{
    public int offsetX = 2, offsetY = 2;
    public RectTransform textRect;
    Vector3 pos;
    
    void Start()
    {
        pos = textRect.localPosition;
    }

    public void Down()
    {
        textRect.localPosition = new Vector3(pos.x + (float)offsetX, pos.y - (float)offsetY, pos.z);
    }

    public void Up()
    {
        textRect.localPosition = pos;
    }
}

Then I have an EventTrigger component attached to the button, put the gameObject in and use the pointerDown and pointerUp events which calls the functions Down() and Up() respectively.
This does not interfere with any onClick() events the buttons has.