0

これを使用してボタンを取得します:

Button button = GameObject.FindGameObjectWithTag("MainCanvas").GetComponentInChildren<Button>();

そして、私は:

void Update()
{
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    RaycastHit hit;
    if (Physics.Raycast(ray, hit))
    {       
        if (button.collider.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), hit))
        { 
            //Code to run when button clicked
        }
    }   
}

ただし、これでエラーが発生し続けます。私がどこで間違ったのか分かりますか?

エラー:

Argument 1: Cannot convert from UnityEngine.Ray to UnityEngine.Vector3 Argument 1: Cannot convert from UnityEngine.RaycastHit to UnityEngine.Vector3 Component.collider is obsolete. Property: collider has been depricated Component does not contain a definition for Raycast and no extension method 'Raycast' accepting a first argument type of 'Component' could be found
4

1 に答える 1

1

のようなフィールドがないためButton.colliderです。コンパイラは、アクセスしようとしているフィールドを認識していません。また、そのフィールドは廃止されたと言っているので、そこに行きます

于 2015-10-08T17:25:17.247 に答える