When an object moves, the opacity moves.

Hello everyone! I am currently making a game in where you need to press a sequence of arrow keys on your keyboard in the correct order at the right time. I want the arrows on the screen to move up every time you press the correct arrow so that the next arrow in the sequence will be in the middle of the screen.

I want the arrows to only be at 100% opacity when in the middle of the screen, but when on the sides, at 50%.

Sorry if I explained that terribly. Thanks!

float targetYPos; // Set this to the target position for 100% opacity
float ySize; // Set this to the distance you want it to take to get from 0% opacity to 100%

void Update () {
    float val = Mathf.Sin((ArrowObject.transform.position.y - targetYPos) / ySize) - 0.5f;
    if (val <= -0.5f || val >= 0.5f) { val = 0.5f; }
    ArrowObject.GetComponent<Sprite> ().color = new Color (val, val, val);
}

.

ArrowObject is a reference to the sprite with the arrows. Change the code from a Sprite to an Image if you need to. I hope this works because I haven’t tested it!