Advertisement
Guest User

TouchButton

a guest
Mar 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5.  
  6. public class keyboardButtonScript : MonoBehaviour {
  7.     public  UnityEvent OnTouch;
  8.     public UnityEvent ExitTouch;
  9.  
  10.     Color defaultColor = new Color (1,1,1,1);
  11.     Color pressedColor = new Color (0.69f,0.69f,0.69f,1);
  12.     SpriteRenderer sr;
  13.  
  14.     AudioSource sound;
  15.  
  16.     // Use this for initialization
  17.     void Start () {
  18.         sr = GetComponent<SpriteRenderer>();
  19.         sound = GetComponent<AudioSource>();
  20.     }
  21.    
  22.     // Update is called once per frame
  23.     void Update () {
  24.        
  25.     }
  26.  
  27.     void OnTouchDown()
  28.     {
  29.         OnTouch.Invoke();
  30.         sr.color = pressedColor;
  31.         sound.PlayScheduled(0);
  32.     }
  33.  
  34.     void OnTouchStay()
  35.     {
  36.         sr.color = pressedColor;
  37.     }
  38.  
  39.     void OnTouchUp()
  40.     {
  41.         ExitTouch.Invoke();
  42.         sr.color = defaultColor;
  43.     }
  44.  
  45.     void OnTouchExit()
  46.     {
  47.        
  48.         sr.color = defaultColor;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement