Unity“Image is an ambiguous reference between 'UnityEngine.UI.Image' and 'UnityEngine.UIElements.Image'”错误

问题描述 投票:0回答:1

导致错误的代码,

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;

public class OyunKontrol : MonoBehaviour
{
    public GameObject secilmisText;
    public GameObject devretPanel;
    public GameObject yaziTuraText;
    public int sonuc = 1;
    public int sira;
    public string yaziTuraCikti = "Tura";
    public string secilmisName;
    public Color player1Color;
    public Color player2Color;
    public Color player3Color;
    public Color player4Color;

    void Start()
    {
        sira = 1;
        print("Saldırmak veya almak istediğiniz şehri seçiniz...");
        secilmisName = null;
**        player1Color = GameObject.Find("Player1").GetComponent<Image>().color;
        player2Color = GameObject.Find("Player2").GetComponent<Image>().color;
        player3Color = GameObject.Find("Player3").GetComponent<Image>().color;
        player4Color = GameObject.Find("Player4").GetComponent<Image>().color;**
    }

粗体代码是错误根源的部分。

我该如何解决?

我尝试删除并重写代码但错误没有解决

c# unity3d user-interface 2d
1个回答
0
投票

这是因为Image类在

UIElement
引用和
Unity UI
中都存在,无法区分这个类属于哪一个。根据你的代码,这个类应该属于Unity UI,所以最好用UI Element去掉。

using UnityEngine.UIElements;
© www.soinside.com 2019 - 2024. All rights reserved.