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.Events;
- public class keyboardButtonScript : MonoBehaviour {
- public UnityEvent OnTouch;
- public UnityEvent ExitTouch;
- Color defaultColor = new Color (1,1,1,1);
- Color pressedColor = new Color (0.69f,0.69f,0.69f,1);
- SpriteRenderer sr;
- AudioSource sound;
- // Use this for initialization
- void Start () {
- sr = GetComponent<SpriteRenderer>();
- sound = GetComponent<AudioSource>();
- }
- // Update is called once per frame
- void Update () {
- }
- void OnTouchDown()
- {
- OnTouch.Invoke();
- sr.color = pressedColor;
- sound.PlayScheduled(0);
- }
- void OnTouchStay()
- {
- sr.color = pressedColor;
- }
- void OnTouchUp()
- {
- ExitTouch.Invoke();
- sr.color = defaultColor;
- }
- void OnTouchExit()
- {
- sr.color = defaultColor;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement