我想知道......在Unity游戏中保存数据的最佳方法是什么.JSONs?如果是这样,怎么样?谢谢
如何从Java调用此C#方法然后返回字符串值?
public string getTest () { return "test"; }
Run Code Online (Sandbox Code Playgroud)
这就是我尝试过的:
String str = UnityPlayer.UnitySendMessage("ProfileSave", "getTest","");
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
Run Code Online (Sandbox Code Playgroud)String str=UnityPlayer.UnitySendMessage("ProfileSave", "getTest",""); ^ required: String found: void
Apple已经强制要求所有应用程序必须支持IPv6 DNS64/NAT64兼容性,并且我正在升级我们的应用程序以执行此操作.在大多数情况下,我们使用的是高级Unity API,所以这不是问题.
但是,在一个应用程序中,我们需要使用较低级别的System.Net.HttpWebRequest接口,以支持稍微复杂的"PUT"操作,以及一些返回的数据.
这被证明是有问题的.当我们尝试HttpWebRequest.BeginGetRequestStream()时,我们在System.Net.HttpWebRequest.SetWriteStreamError中得到一个NameResolutionFailure异常.我们在普通的IPv4网络上看不到此例外.
这向我表明DNS失败,因此我们使用HttpWebRequest的方式出了问题.HttpWebRequest是否与.Net版本Unity使用(.NET 2.0)不符合IPv6?我没有成功搜索文档.
此时我的下一步是开始编写套接字级代码以在此应用程序中支持IPv6,或者为iOS编写自定义插件.这些都不是我想要追求的途径,所以我希望其他人能提出更好的计划.
Unity中是否有一种方法可以在不使用UI层的情况下创建简单的2D按钮.我有一个有很多按钮的游戏,我不想在UI中制作整个应用程序.还欢迎更多控件:开关,滑块等.
PS.我看到了NGUI,到目前为止我还不喜欢它.还要别的吗?
我试图将我的所有非Unity特定代码移动到不继承的类中MonoBehaviour,类似于此.我Models为所有非MonoBehaviour类创建了一个单独的Visual Studio项目,并将该项目添加到Visual Studio解决方案中.但是,我无法Models通过Visual Studio向我的Unity项目添加对项目的引用(当我单击Unity项目时,Add Reference按钮不存在,我已经读过Unity无论如何都会自动重建它的Visual Studio项目,所以任何添加的引用都会丢失),所以我将Models.dll 的输出位置设置为Unity中的Assets文件夹,然后我将.dll添加到Unity的Project视图中.这一切都奏效了.问题是每当我重建我的Models项目时,Visual Studio中的Unity项目似乎都没有获取更改,所以我必须从Unity的Project视图中删除.dll并在每次我做任何时重新添加它.对Models项目的更改.
有没有办法让Visual Studio自动查看我的Models.dll 的更改,还是有更好的方法让我的Unity项目引用另一个Visual Studio项目?
我正在尝试使用 Linerenderer 在两个 UI 游戏对象之间画一条线。在场景模式下一切正常,但在游戏模式下线是不可见的。我试图改变对象的 Z 位置,但线条仍然不可见。谁能帮我?提前致谢
private LineRenderer lineRenderer;
private float counter;
private float dist;
private Vector3 aPos;
private Vector3 bPos;
public Transform origin;
public Transform destination;
public float lineDrawSpeed = 6f;
// Use this for initialization
void Start()
{
lineRenderer = GetComponent<LineRenderer>();
aPos = new Vector3(origin.position.x, origin.position.y, origin.position.z); // Using these to move the lines back
bPos = new Vector3(destination.position.x, destination.position.y, destination.position.z);
lineRenderer.SetPosition(0, aPos);
lineRenderer.SetWidth(3f, 3f);
dist = Vector3.Distance(origin.position, destination.position);
}
// Update is called once per frame …Run Code Online (Sandbox Code Playgroud) 我正在开发 2D Unity 应用程序,但遇到了一些奇怪的行为。
这段代码工作得很好。
Debug.DrawLine(button1.transform.position, button2.transform.position, Color.green);
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,我在场景视图中看到一条绿线。
但是当我有以下行时,游戏视图中没有任何显示。
Physics2D.Linecast(button1.transform.position, button2.transform.position);
Run Code Online (Sandbox Code Playgroud)
我对 Unity 如何能够在这两个按钮之间画一条线感到困惑,但出于某种原因,它只是不在游戏视图中这样做。
知道如何解决这个问题吗?
编辑:解决了。使用TextMeshProUGUI代替TextMeshPro。
背景:
我使用 TextMeshPro 来显示文本。我想通过脚本更改文本。问题是当我尝试更改它时会收到 NullReferenceException。
细节:
我的脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class UI_speed : MonoBehaviour {
TextMeshPro textmeshPro;
void Start () {
textmeshPro = GetComponent<TextMeshPro>();
textmeshPro.text = "test";
}
}
Run Code Online (Sandbox Code Playgroud)
代码与TextMeshPro API匹配,所以我不确定发生了什么。我正在使用 Unity 5.6.1f1。任何帮助是极大的赞赏。谢谢你。

我正在尝试将 Firebase 远程配置实施到统一项目中。
这是唯一正在运行的脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Firebase;
using Firebase.RemoteConfig;
using System;
using System.Threading.Tasks;
public class FirebaseAlt : MonoBehaviour
{
private DependencyStatus dependencyStatus = DependencyStatus.UnavailableOther;
void Awake()
{
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
dependencyStatus = task.Result;
if (dependencyStatus == DependencyStatus.Available)
{
InitializeFirebase();
}
else
{
Debug.LogError("Could not resolve all Firebase dependencies: " + dependencyStatus);
}
});
}
// Initialize remote config, and set the default values.
void InitializeFirebase()
{
FetchData();
}
// Start a fetch request.
public void …Run Code Online (Sandbox Code Playgroud) unity5 ×10
c# ×4
android ×1
c#-2.0 ×1
firebase ×1
ipv6 ×1
json ×1
persistence ×1
saving-data ×1
text ×1
unity3d-ui ×1
unityscript ×1