# How do I make a 2D sprite flash green when tapped?

I have a sprite that is based on an image of a gray circle. When the user touches the sprite, I want the sprite to flash green, as in I want the circle to appear to turn green for 0.2 seconds. I tried setting the color of the sprite via SpriteRenderer's function SetColor, and it blended the color with the initial gray color of the sprite, so I got a very dark green even though I'm really sure I didn't mess up the values when I created the color. Now I'm trying to get my flashing effect by using separate images. I have the images I need, and I have a message getting logged when I tap the circle, I just need to setup a non-looping animation and trigger that animation in my code.

• Can we see, what you have got so far? – Ahmet Zambak Dec 12 '15 at 0:27
• I second @AhmetZambak. It's somewhat clear what you want to achieve but the description is too abstract. You might increase the chances of success of your question if you give details of what you have so answers can delve on it to propose something useful. – MAnd Dec 12 '15 at 1:12

I figured it out after learning about the animation editor (if that's what it's called). I'm using two sprites. Both of them are circles, but one is gray and the other is green. I used the animation editor to create an idle animation that just replaces whatever the current sprite is with the gray sprite from my Assets folder. I created a parameter ShouldFlashGreen of type trigger that triggers the green animation to start. When the green animation starts, it replaces whatever sprite is currently being used with the green sprite from my Assets folder. When it stops, it goes back to the idle animation. I then attached a C# script to my Sprite object. Here's the code in the script:

using UnityEngine;
using System.Collections;

public class TapHandler : MonoBehaviour {

private Collider2D circleCollider;
private Animator animator;

void Awake () {
circleCollider = GetComponent<Collider2D> ();
animator = GetComponent<Animator> ();
}

void Update () {
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) {
Touch firstTouch = Input.GetTouch(0);

Vector3 worldPoint = Camera.main.ScreenToWorldPoint(firstTouch.position);
Vector2 touchPoint = new Vector2 (worldPoint.x, worldPoint.y);

if (circleCollider == Physics2D.OverlapPoint (touchPoint)) {
animator.SetTrigger("ShouldFlashGreen");
}
}
}
}