- Home /
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!
Answer by DawdleDev · Oct 02, 2018 at 10:36 PM
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!
It works great! I am editing it a bit to fit it in best with my game though! Thanks!
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Making a bubble level (not a game but work tool) 1 Answer
How to move the character to bottom left/right? 0 Answers
Moving my character horizontally and vertically at diffrent times 1 Answer
Stop on a Dime Character Movement 1 Answer