Exemplo n.º 1
0
    ///<summary>單選取物件</summary>
    void SelectObj()
    {
        Vector2    mousePosition = Input.mousePosition;
        Ray        ray           = Camera.main.ScreenPointToRay(mousePosition);
        RaycastHit hit;

        //選擇物體
        if (Physics.Raycast(ray, out hit, 10, SelectableLayers))
        {
            PickableObject item = hit.collider.GetComponent <PickableObject>();
            if (item != null &&
                hit.collider.GetComponent <NavMeshAgent>() != null)
            {
                if (!SelectingObjs.Exists(e => e == item))
                {
                    SelectingObjs.Add(item);
                    item.GotChosen();
                }
            }
        }
    }