5395人加入学习
(33人评价)
UGUI整体解决方案-案例篇(Unity 2019.1.0f2)

2019-08-02

价格 ¥ 338.00
该课程属于 Unity - A计划(永久有效期) 请加入后再学习

解决UI和3D物体同时响应的问题。

在ColliderUI代码里面加上:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class ColliderUI : MonoBehaviour ,IPointerClickHandler{

    private int _index;
	// Use this for initialization
	void Start () {
		
	}

    public void ChangeColor()
    {
        if (_index == 0)
        {
            GetComponent<Image>().color = Color.blue;
        }
        else {
            GetComponent<Image>().color = Color.white;
        }
        _index = _index == 0 ? 1 : 0;
    }

public void OnPointerClick(PointerEventData eventData)
{
 	ChangeColor();
   // ExecuteAll(eventData);
}

public void ExecuteAll(PointerEventData eventData) {
    List<RaycastResult> results = new List<RaycastResult>();
    EventSystem.current.RaycastAll(eventData, results);
    foreach (RaycastResult result in results) {
        if (result.gameObject != gameObject)
        {
            ExecuteEvents.Execute(result.gameObject, eventData, ExecuteEvents.pointerClickHandler);
        }
    }
}
}

 

[展开全文]

痾痾痾痾痾  痾痾痾痾痾痾痾痾痾痾痾 建議X2 

[展开全文]