【问题标题】:Cannot convert from 'method group' to 'IEnumerator' [closed]无法从“方法组”转换为“IEnumerator”[关闭]
【发布时间】:2018-03-23 15:10:21
【问题描述】:

我对 Unity 非常非常陌生。

我已经按照教程将 Google 映射到原始图像的脚本。但是我遇到了一个错误,不知道如何解决它。

谁能帮帮我?

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

public class GoogleAPI : MonoBehaviour
{
    public string url;

    public RawImage img;

    public float lon;
    public float lat;

    public int zoom = 14;
    public int mapWidth = 600;
    public int mapHeight = 620;

    LocationInfo li;

    public enum mapType { roadMap, satelite, hybrid, terrain };
    public mapType MapSelected;

    public int scale;

    IEnumerator Map()
    {
        url = "https://maps.googleapis.com/maps/api       /staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=13&size=600x300&maptype=roadmap \n" +
                " & markers = color:blue % 7Clabel: S % 7C40.702147,-74.015794 & markers = color:green % 7Clabel: G % 7C40.711614,-74.012318 \n" +
                " & markers = color:red % 7Clabel: C % 7C40.718217,-73.998284 & key =  AIzaSyDh1_nS-l7nWOFWvt0Gg9-9dY_11qWzK_Q ";
        WWW www = new WWW(url);
        yield return www;
        img.texture = www.texture;
        img.SetNativeSize();
    }


    // Use this for initialization
    void Start()
    {
        img = gameObject.GetComponent<RawImage>();
        StartCoroutine(Map);

    }

    // Update is called once per frame
    void Update()
    {

    }
}

错误在 StartCoroutine (Map);

(地图)。我得到“参数 1:无法将 '方法组' 转换为 'IEnumerator'”

在视频中,这位老兄做到了,而且效果很好,所有评论似乎都是通过这种方法获得成功的人。我没有。

提前致谢!

【问题讨论】:

  • 你缺少括号:StartCoroutine (Map());

标签: c# unity3d mobile


【解决方案1】:

这会传递方法/方法组,而不是方法的结果:

 StartCoroutine(Map);

这会执行方法并返回结果,并将其传递给您的 Coroutine 方法:

 StartCoroutine(Map());

每当您收到有关方法组的强制转换或转换错误时,请查找您忘记括号的位置。

【讨论】:

    【解决方案2】:

    启动协程有两种方式。

    一种是直接将例程作为参数传递

     StartCoroutine(Map());
    

    或者使用方法的字符串名称但是这个版本启动协程有更高的运行时开销。

     StartCoroutine("Map");
    

    【讨论】:

      猜你喜欢
      • 2022-01-06
      • 2021-06-25
      • 2013-10-02
      • 1970-01-01
      • 2010-10-18
      • 2015-04-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多