TutorialIndicator.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class TutorialIndicator : MonoBehaviour
  7. {
  8. public bool swipe;
  9. float speed = 0.25f;
  10. Image image;
  11. // Use this for initialization
  12. void Start()
  13. {
  14. image = GetComponent<Image>();
  15. }
  16. public void Swipe()
  17. {
  18. gameObject.SetActive(true);
  19. swipe = true;
  20. transform.position = new Vector3(Screen.width * 0.7f, Screen.height * 0.7f, 5);
  21. }
  22. // Update is called once per frame
  23. void Update()
  24. {
  25. if (!swipe)
  26. {
  27. //print(transform.position);
  28. transform.localScale = Vector3.one * (1 + Mathf.Sin(Time.time * 2) * 0.15f);
  29. }
  30. else
  31. {
  32. //float speed = 0.25f;
  33. if (image.enabled)
  34. {
  35. transform.position += Vector3.left * Time.deltaTime * (Screen.width * speed);
  36. speed += Time.deltaTime * 0.75f;
  37. if (transform.position.x < Screen.width * 0.3f)
  38. {
  39. image.enabled = false;
  40. StartCoroutine(ResetHand());
  41. }
  42. }
  43. }
  44. }
  45. private IEnumerator ResetHand()
  46. {
  47. yield return new WaitForSeconds(0.5f);
  48. image.enabled = true;
  49. transform.position = new Vector3(Screen.width * 0.7f,
  50. Screen.height * 0.7f, 5);
  51. speed = 0.15f;
  52. }
  53. public void Stop()
  54. {
  55. swipe = false;
  56. gameObject.SetActive(false);
  57. }
  58. }