C#和#xFF1A;名称';推出';在当前上下文中不存在
这是我的二维码追踪码。使用gitHub示例并添加了一个名为“Launch”的新函数C#和#xFF1A;名称';推出';在当前上下文中不存在,c#,unity3d,C#,Unity3d,这是我的二维码追踪码。使用gitHub示例并添加了一个名为“Launch”的新函数 public void Launch(string uri) 当我稍后调用它时,它给出: The name 'Launch' does not exist in this current context 我的声明是错误的还是应该包含在“QRTracking”函数中?使用,Unity 2019.4.14f1,Visual Studio 2019,UWP平台。我已经删除了带有“…”的部分代码,以减小我认为不相关的
public void Launch(string uri)
当我稍后调用它时,它给出:
The name 'Launch' does not exist in this current context
我的声明是错误的还是应该包含在“QRTracking”函数中?使用,Unity 2019.4.14f1,Visual Studio 2019,UWP平台。我已经删除了带有“…”的部分代码,以减小我认为不相关的大小。任何提示都会非常有用。我在C#是个新手
在C#中,您必须向类添加方法,它们不能在名称空间中是独立的
将您的
public void Launch(string uri)
方法定义移动到一个类中,那么它至少应该编译。它不在类范围内。把它搬到教室里去。谢谢!将“public void Launch”移动到“QRTracking”后,错误消失了。@Fakir怀疑。。它现在可能在类QRCode
中,而不仅仅在名称空间qrcracking
using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;
#if WINDOWS_UWP
using Windows.Perception.Spatial;
public void Launch (string uri)
{
Debug.Log($"LaunchUri: Launching {uri}"); #if WINDOWS_UWP
UnityEngine.WSA.Application.InvokeOnUIThread(async () =>
{
bool result = await global::Windows.System.Launcher.LaunchUriAsync(new
System.Uri(uri));
if (!result)
{
Debug.LogError("Launching URI failed to launch.");
}
}, false); #else
Application.OpenURL(uri);
#endif
}
#endif
namespace QRTracking
{
[RequireComponent(typeof(QRTracking.SpatialGraphCoordinateSystem))]
public class QRCode : MonoBehaviour
{
public Microsoft.MixedReality.QR.QRCode qrCode;
private GameObject qrCodeCube;
....
....
private bool launch = false;
private System.Uri uriResult;
private long lastTimeStamp = 0;
// Use this for initialization
void Start()
{
PhysicalSize = 0.1f;
CodeText = "Dummy";
if (qrCode == null)
{
throw new System.Exception("QR Code Empty");
}
PhysicalSize = qrCode.PhysicalSideLength;
CodeText = qrCode.Data;
....
....
QRID.text = "Id:" + qrCode.Id.ToString();
QRNodeID.text = "NodeId:" + qrCode.SpatialGraphNodeId.ToString();
QRText.text = CodeText;
if (System.Uri.TryCreate(CodeText, System.UriKind.Absolute,out uriResult))
{
validURI = true;
QRText.color = Color.blue;
}
...
...
Debug.Log("Id= " + qrCode.Id + "NodeId= " + qrCode.SpatialGraphNodeId + " PhysicalSize
= " + PhysicalSize + " TimeStamp = " + qrCode.SystemRelativeLastDetectedTime.Ticks + "
QRVersion = " + qrCode.Version + " QRData = " + CodeText);
// added here
Debug.Log("Call Launch");
Launch("http://" + CodeText"); // -> error: Name 'Launch' does not exist in the
current context
}
.....
.....