Game Development Reference
In-Depth Information
made about the emotional influence of graphical and audible feedback in software, and especially in
games. It seems possible that the aggregate effects of even the smallest tokens of feedback, such
as a ping or swoosh sound played when achievements are made, can contribute toward a more
rewarding and satisfying feeling in-game, leading to greater emotional attachments between the
gamer and the game.
But even without these studies and theories, I'm guessing most of us have felt emotionally rewarded
and gratified firsthand whenever a game acknowledges our successes or correct moves. At least,
I know I have! So, let's add some visual feedback to CMOD for enemy damage events by making the
Enemy flicker red when damage is taken. To do this, I'll create a new class, PingPongSpriteColor ,
which works much like the PingPong movement script created for power-up objects in Chapter 4,
except here the script will ping-pong between sprite material colors, allowing us to transition a sprite
from one color to another over a specified time. Listing 7-3 lists that class in full.
Listing 7-3. PingPongSpriteColor.cs: Transitions Between Material Colors
01 //Sets color for all child sprite renderers in a gameobject
02 //------------------------------------------------
03 using UnityEngine;
04 using System.Collections;
05 //------------------------------------------------
06 public class PingPongSpriteColor : MonoBehaviour
07 {
08 //Source (from) color
09 public Color Source = Color.white;
10
11 //Destination (to) color
12 public Color Dest = Color.white;
13
14 //Custom ID for this animation
15 public int AnimationID = 0;
16
17 //Total time in seconds to transition from source to dest
18 public float TransitionTime = 1.0f;
19
20 //List of sprite renders whose color must be set
21 private SpriteRenderer[] SpriteRenderers = null;
22
23 //------------------------------------------------
24 // Use this for initialization
25 void Start ()
26 {
27 //Get all child sprite renderers
28 SpriteRenderers = GetComponentsInChildren<SpriteRenderer>();
29 }
30 //------------------------------------------------
31 public void PlayColorAnimation(int AnimID = 0)
32 {
33 //If Anim ID numbers do not match, then exit - should not play this animation
34 if(AnimationID != AnimID) return;
35
 
Search WWH ::




Custom Search