C# 通过更改脚本2中的下拉值来更改脚本1中的枚举状态&引用;是否缺少程序集引用?“;
我得到的错误是“您是否缺少程序集引用?”C# 通过更改脚本2中的下拉值来更改脚本1中的枚举状态&引用;是否缺少程序集引用?“;,c#,unity3d,C#,Unity3d,我得到的错误是“您是否缺少程序集引用?” 使用系统集合; 使用System.Collections.Generic; 使用UnityEngine; 使用UnityEngine.UI; 公共类下拉控制器:MonoBehavior{ //在hierarch中的下拉对象,这些变量在开关中被检查 更新函数中的案例 公共下拉地图类型、位置; //GoogleAPI脚本的句柄,该脚本包含带有MapType的GoogleMaps代码 和位置枚举。 公共GoogleAPI _mapSelected,_locat
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
使用UnityEngine.UI;
公共类下拉控制器:MonoBehavior{
//在hierarch中的下拉对象,这些变量在开关中被检查
更新函数中的案例
公共下拉地图类型、位置;
//GoogleAPI脚本的句柄,该脚本包含带有MapType的GoogleMaps代码
和位置枚举。
公共GoogleAPI _mapSelected,_locationSelected;
//用于初始化
无效开始()
{
//调用填充下拉列表的PopulatedDropDown函数
PopulateDropDowns();
//从GoogleAPI脚本获取枚举
_locationSelected.GetComponent();
_mapSelected.GetComponent();
}
//用选项填充下拉列表
public void PopulateDropDowns()
{
//更改标题文本
locations.GetComponent().captionText.text=“Location”;
mapType.GetComponent().captionText.text=“映射类型”;
列表位置名称=新列表
{
“Pentraeth森林”//0
“纽伯勒森林”//1
“其他森林”//2
};
//获取字符串列表并将其添加到“位置”下拉列表中
locations.GetComponent().AddOptions(locationNames);
//与上面相同,但适用于Maptype。
列表mapTypeNames=新列表
{
“路线图”//0
“卫星”//1
“Hybrid”//2
“地形”//3
};
mapType.GetComponent().AddOptions(mapTypeNames);
}
//每帧调用一次更新
无效更新()
{
//开关箱,以检查下拉列表中的值。
开关(位置.值)
{
案例0:
Debug.Log(“Pentraeth”);
//如果下拉列表的值为0,请更改位置枚举的状态
在谷歌API中,Pentraeth。
试一试{
_locationSelected.locationSelected=
GoogleAPI.Locations.Pentraeth;
Log(“枚举更改为Pentraeth”);}
接住
{
Log(“错误,枚举不能更改为Pentraeth”);
}
打破
案例1:
Debug.Log(“Newbough”);
尝试
{
_locationSelected.locationSelected=
GoogleAPI.Locations.Newborough;
Log(“Enum改为Newborough”);
}
接住
{
Log(“错误,枚举不能更改为Newborough”);
}
打破
案例2:
Debug.Log(“另一个”);
尝试
{
_locationSelected.locationSelected=
GoogleAPI.Locations.other;
Log(“枚举已更改为另一个”);
}
接住
{
Log(“错误,无法将枚举更改为另一个”);
}
打破
}
}
}
我有一个包含下拉脚本的dropdowncontroller对象,然后我将两个下拉对象拖到脚本中
具有枚举的GoogleAPi脚本位于作为映射的rawimage对象中。在GoogleAPI脚本中没有对下拉列表的引用。只有枚举。应该有吗
“缺少组件参考错误适用于3”\u locationSelected.locationSelected=GoogleAPI.Locations.Pentraeth;"
“_locationSelected.locationSelected=GoogleAPI.Locations.Newborough;"
“_locationSelected.locationSelected=GoogleAPI.Locations.other;"
我们的想法是有两种切换情况。1检查Locationsdropdown值,然后更改已选择变量Location的位置枚举的状态,然后更改lat和lon坐标,然后生成新地图
另一个开关盒应该执行完全相同的逻辑,但更改maptype,而不是lat和lon
我已将交换机置于try,catch中,以便获取一些debug.log,对吗
我想我已经够清楚了!错误似乎很清楚。您需要在文档顶部添加一个引用googleapi的using语句。修复了它。我猜这是一个错误,因为Unity和Visual Studio只需要重新启动。现在错误已经消失
因此,如果有人收到“Error CS1061:you missing a assembly reference”(错误CS1061:you's missing a assembly reference)并且一切看起来都正常,只要重新启动就行了。对我来说,我看到了另一个线程,它也对他们起作用。您的意思是像“using GoogleAPI;”一样,GoogleAPI是脚本名称,它位于下拉脚本的顶部?
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;
}
}
}