Advertisement
l3enjamin

Chip's Tunes - Faces.cs

May 8th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Faces : MonoBehaviour {
  7.  
  8.     public Sprite FLeft, NLeft, NRight, FRight, Neutral;
  9.     SpriteRenderer SR;
  10.     public float T;
  11.  
  12.     void Start () {
  13.         SR = GetComponent<SpriteRenderer> ();
  14.         T = 0f;
  15.     }
  16.  
  17.     void Update () {
  18.         //T increases by time since last frame (real world time), if the player presses D, run the
  19.         //FarLeftFunction and set T to 0, the FarLeftFunction changes Chip's sprite to be looking FarLeft
  20.         //If the value of T is between 79 and 86, make Chip's sprite return to the neutral position
  21.         T += Time.deltaTime;
  22.         if (Input.GetKeyDown (KeyCode.D)) {
  23.             FLeftF ();
  24.             T = 0;
  25.         }
  26.         if (Input.GetKeyDown (KeyCode.G)) {
  27.             NLeftF ();
  28.             T = 0;
  29.         }
  30.         if (Input.GetKeyDown (KeyCode.J)) {
  31.             NRightF ();
  32.             T = 0;
  33.         }
  34.         if (Input.GetKeyDown (KeyCode.H)) {
  35.             FRightF ();
  36.             T = 0;
  37.         }
  38.         test ();
  39.     }
  40.     void FLeftF (){
  41.         SR.sprite = FLeft;
  42.     }
  43.     void NLeftF (){
  44.         SR.sprite = NLeft;
  45.     }
  46.     void NRightF (){
  47.         SR.sprite = NRight;
  48.     }
  49.     void FRightF (){
  50.         SR.sprite = FRight;
  51.     }
  52.     void NeutralF () {
  53.         SR.sprite = Neutral;
  54.     }
  55.     void test () {
  56.         if (T >= 80 && T <= 85) {
  57.             NeutralF ();
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement