找不到类型或命名空间名称"NativeShare"(是否缺少 using 指令或程序集引用?



我正在使用本机共享unity游戏。但是我遇到了这个错误。如何解决这个问题?

目录
using UnityEngine;
using UnityEngine.UI;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using GooglePlayGames.BasicApi.SavedGame;
using System.IO;
using System.Collections;

本地共享代码

private IEnumerator TakeScreenshotAndShare()
{
yield return new WaitForEndOfFrame();
Texture2D ss = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
ss.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
ss.Apply();
string filePath = Path.Combine(Application.temporaryCachePath, "shared img.png");
File.WriteAllBytes(filePath, ss.EncodeToPNG());
// To avoid memory leaks
Destroy(ss);
new NativeShare().AddFile(filePath).SetSubject("Control The Pandemic").SetText("I found this game most attractive!").Share();
}
public void ShareGame()
{
StartCoroutine(TakeScreenshotAndShare());
}

误差

CS0246: The type or namespace name 'NativeShare' could not be found (are you missing a using directive or an assembly reference?)

您可能需要将using NativeShare添加到脚本的顶部。

如果这不是问题,如果NativeShare有自己的程序集定义文件,这些文件有时会在Unity中无缘无故地崩溃。在这种情况下,关闭一切(unity visual studio等),删除unity临时文件夹(library, obj在你的项目的根目录),并再次打开项目。

Sol 1 -尝试关闭Unity, Unity HUB, VS Code并重新打开。

(Alternate) Sol 2 -关闭VS Code后,尝试Unity ->偏好→外部工具->Regenerate project files.

相关内容

最新更新