我得到的错误是“你缺少装配参考吗?”
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DropdownControllers : MonoBehaviour {
//Dropdown objects in hierarch, these variables are checked in the switch
cases in update function
public Dropdown mapType, locations;
// Handle to GoogleAPI script which has the google maps code with MapType
and Locations enums.
public GoogleAPI _mapSelected, _locationSelected;
// Use this for initialization
void Start ()
{
//Calls populateDropDown function which populates the dropdown
PopulateDropDowns();
//Gets enums from GoogleAPI script
_locationSelected.GetComponent<GoogleAPI>();
_mapSelected.GetComponent<GoogleAPI>();
}
//Populates dropdowns with options
public void PopulateDropDowns()
{
//Changes the caption text
locations.GetComponent<Dropdown>().captionText.text = "Location";
mapType.GetComponent<Dropdown>().captionText.text = "Map type";
List<string> locationNames = new List<string>
{
"Pentraeth Forest", //0
"Newborough Forest", //1
"Other Forest" //2
};
//take the list of strings and add them to locations dropdown
locations.GetComponent<Dropdown>().AddOptions(locationNames);
//Same as above but for Maptype.
List<string> mapTypeNames = new List<string>
{
"Roadmap", //0
"Satellite", //1
"Hybrid", //2
"Terrain" //3
};
mapType.GetComponent<Dropdown>().AddOptions(mapTypeNames);
}
// Update is called once per frame
void Update ()
{
//Switch case to check the value in dropdown.
switch (locations.value)
{
case 0:
Debug.Log("Pentraeth");
//if value of dropdown is 0, change the state of locations enum
within the Google API to Pentraeth.
try {
_locationSelected.locationSelected =
GoogleAPI.Locations.Pentraeth;
Debug.Log("Enum changed to Pentraeth"); }
catch
{
Debug.Log(" Error, Enum cannot be changed to Pentraeth");
}
break;
case 1:
Debug.Log("Newbough");
try
{
_locationSelected.locationSelected =
GoogleAPI.Locations.Newborough;
Debug.Log("Enum changed to Newborough");
}
catch
{
Debug.Log(" Error, Enum cannot be changed to Newborough");
}
break;
case 2:
Debug.Log("Another");
try
{
_locationSelected.locationSelected =
GoogleAPI.Locations.Another;
Debug.Log("Enum changed to Another");
}
catch
{
Debug.Log(" Error, Enum cannot be changed to Another");
}
break;
}
}
}
我有一个带有下拉脚本的dropdowncontroller对象,然后我将两个下拉对象拖到脚本中。
包含枚举的GoogleAPi脚本位于rawimage对象中,即地图。没有提及GoogleAPI脚本中的下拉列表。只有枚举。应该有吗?
“缺少程序集引用错误是针对3”_locationSelected.locationSelected = GoogleAPI.Locations.Pentraeth;“ “_locationSelected.locationSelected = GoogleAPI.Locations.Newborough;” “_locationSelected.locationSelected = GoogleAPI.Locations.Another;”
这个想法将是2个开关案例。 1检查Locationsdropdown值,然后更改具有变量locationSelected的Locations枚举的状态,然后更改lat和lon坐标,然后生成新地图。
另一个开关案例应该完全相同的逻辑,但改变maptype而不是lat和lon。
我把开关盒放在try中,因此我可以得到一些debug.logs,这是正确的吗?
认为我已经足够清楚了!
答案 0 :(得分:2)
错误似乎很清楚。您需要在引用googleapi的文档顶部添加using语句。
答案 1 :(得分:0)
修正了它。猜猜这是一个错误,因为Unity和Visual Studio只需要重启。现在错误消失了。
所以如果有人得到'错误CS1061:你错过了程序集引用吗?'一切看起来还不错。刚刚重启。为我工作,我看到了另一个线程,它也为他们工作。