根据按钮点击更改雷达图像

时间:2017-11-14 20:57:55

标签: c# unity3d

我可以帮忙。我有一个显示物体的雷达。我尝试引入雷达扫描功能,以便在单击按钮时,雷达上的图像会根据对象的标记进行更新。我的代码没有错误,但我无法让它工作,并希望有人在这里发现问题所在。谢谢!!!!

RadarScan脚本

N

雷达脚本

commands:
    000_sudo:
        command: sudo su
    001_cd_to_app:
        command: cd /var/app/current
    002_rm_solr:
        command: rm -rf solr/
    003_start_solr:
        command: bundle exec rails sunspot:solr:start RAILS_ENV=production
    004_reindex_solr:
        command: bundle exec rails sunspot:solr:reindex RAILS_ENV=production

}

MakeRadarObject脚本

public class RadarScan : MonoBehaviour {

public Image RadarImageToChange;

public void ChangeImage(Image UpdateImage)
{
    if(gameObject.tag == "Enemy")
    {
        UpdateImage = RadarImageToChange;
    }

}

}

1 个答案:

答案 0 :(得分:1)

您不是将Image应用于游戏对象,而是仅应用于名为UpdateImage的变量。您需要获取游戏对象的图像组件,然后将新图像分配给它。您还需要将图像更改为Sprite的形式才能使其生效。

public Sprite RadarImageToChange;

public void ChangeImage(Sprite UpdateImage)
{
        if(gameObject.tag == "Enemy")
        {
            gameObject.GetComponent<Image>().sprite = RadarImageToChange;
        }
}
相关问题