当前位置:   article > 正文

unity RawImage ui的鼠标事件处理、日志打印、纹理更换,进入其他场景_raw image触发点击事件

raw image触发点击事件

 

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. //using UnityEngine.Events;
  5. //using UnityEngine.EventSystems;
  6. using UnityEngine.UI;
  7. using UnityEngine.Events;
  8. using UnityEngine.EventSystems;
  9. public class menu_start : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler
  10. {
  11. public AudioClip audioClip;
  12. private AudioSource audioPlayer;
  13. public Texture2D texture_enter;
  14. public Texture2D texture_exit;
  15. private RawImage rawImage;
  16. // Start is called before the first frame update
  17. void Start()
  18. {
  19. audioPlayer = GetComponent<AudioSource>();
  20. rawImage = GetComponent<RawImage>();
  21. }
  22. // Update is called once per frame
  23. void Update()
  24. {
  25. }
  26. void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData) {
  27. Debug.Log("EventTriggerTest OnPointerEnter");
  28. playAudio();
  29. rawImage.texture = texture_enter;
  30. }
  31. void IPointerExitHandler.OnPointerExit(PointerEventData eventData)
  32. {
  33. Debug.Log("EventTriggerTest OnPointerExit");
  34. //playAudio();
  35. rawImage.texture = texture_exit;
  36. }
  37. void IPointerDownHandler.OnPointerDown(PointerEventData eventData)
  38. {
  39. Debug.Log("EventTriggerTest OnPointerDown");
  40. if (gameObject.tag == "menu_play")
  41. {
  42. Debug.Log("EventTriggerTest menu_play");
  43. StartCoroutine(toMain());
  44. }
  45. else if (gameObject.tag == "menu_introduce")
  46. {
  47. Debug.Log("EventTriggerTest menu_introduce");
  48. StartCoroutine(toIntroduce());
  49. }
  50. else if (gameObject.tag == "menu_quit") {
  51. Debug.Log("EventTriggerTest menu_quit");
  52. StartCoroutine(quit());
  53. }
  54. playAudio();
  55. }
  56. void playAudio() {
  57. audioPlayer.clip = audioClip;
  58. audioPlayer.Play();
  59. }
  60. IEnumerator quit()
  61. {
  62. yield return new WaitForSeconds(1.0f);
  63. Application.Quit();
  64. }
  65. IEnumerator toMain()
  66. {
  67. yield return new WaitForSeconds(1.0f);
  68. Application.LoadLevel("SceneMain");
  69. }
  70. IEnumerator toIntroduce()
  71. {
  72. yield return new WaitForSeconds(1.0f);
  73. Application.LoadLevel("SceneIntroduce");
  74. }
  75. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/127633
推荐阅读
相关标签
  

闽ICP备14008679号