Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class Faces : MonoBehaviour {
- public Sprite FLeft, NLeft, NRight, FRight, Neutral;
- SpriteRenderer SR;
- public float T;
- void Start () {
- SR = GetComponent<SpriteRenderer> ();
- T = 0f;
- }
- void Update () {
- //T increases by time since last frame (real world time), if the player presses D, run the
- //FarLeftFunction and set T to 0, the FarLeftFunction changes Chip's sprite to be looking FarLeft
- //If the value of T is between 79 and 86, make Chip's sprite return to the neutral position
- T += Time.deltaTime;
- if (Input.GetKeyDown (KeyCode.D)) {
- FLeftF ();
- T = 0;
- }
- if (Input.GetKeyDown (KeyCode.G)) {
- NLeftF ();
- T = 0;
- }
- if (Input.GetKeyDown (KeyCode.J)) {
- NRightF ();
- T = 0;
- }
- if (Input.GetKeyDown (KeyCode.H)) {
- FRightF ();
- T = 0;
- }
- test ();
- }
- void FLeftF (){
- SR.sprite = FLeft;
- }
- void NLeftF (){
- SR.sprite = NLeft;
- }
- void NRightF (){
- SR.sprite = NRight;
- }
- void FRightF (){
- SR.sprite = FRight;
- }
- void NeutralF () {
- SR.sprite = Neutral;
- }
- void test () {
- if (T >= 80 && T <= 85) {
- NeutralF ();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement