Tag: unity3d

Unity中的REST(从网络服务器发送消息到统一)

有没有办法让一个简单的网络服务器向Unity发送消息? 目前,我们正在使用更新方法中的UnityWebRequest.Get()进行GET 。 这是代码: // Update is called once per frame void Update () { StartCoroutine(GetData()); } IEnumerator GetData() { UnityWebRequest uwr = UnityWebRequest.Get(url); yield return uwr.Send(); if (uwr.isError) { Debug.Log(uwr.error); }else { Debug.Log((float.Parse(uwr.downloadHandler.text) / 100)); fnumber = ((float.Parse(uwr.downloadHandler.text) / 100)); transform.position.Set(oldX, fnumber, oldZ); } } 但是,这会抛出此错误: 无法解决目的地主机问题 我发现这个错误报告,它说,它本来是固定的,但似乎并非如此。 那么,有没有办法让服务器向Unity发送消息? 谢谢

如何检测UI和GameObjects上的点击/触摸事件

如何在Android上的Canvas on Touch上检测UI对象? 例如,我有一个canvas,有5个对象,如Image , RawImage , Buttons , InputField等。 当我触摸按钮UI对象然后做一些事情。 单击依赖时,每个按钮执行不同的过程。 代码如下所示: private void Update() { if (Input.touches.Length <= 0) return; for (int i = 0; i < Input.touchCount; i++) { if (Button1.touch) if (Input.GetTouch(i).phase == TouchPhase.Began) login(); else if (Button2.touch && Input.GetTouch(i).phase == TouchPhase.Began) LogOut(); } } 那怎么办呢? 第二:如何检测Gameobject获取触摸? 是否与上述相同?

使用关键字Unity查找GameObjects

如何在Unity中找到带有关键字的GameObjects? 实际上,我有很多GameObject这样命名: 混凝土楼[289483] 混凝土楼[289487] 墙壁部分[293291] 部分[321043] … 我已经创建函数来获取对象的ID(在[]括号内),因为它是GameObject名称的相关部分。 ID应该是唯一的,但我不确定它是什么! 现在,我希望有一个这个原型的function: public static GameObject[] getObjectsWithIdentifier(int identifier) 它将返回具有参数中给出的标识符的所有对象。 所以它就像一个搜索function。 GameObject.Find(name) ,据我所知,只搜索对象的确切名称。 谢谢你的帮助 !

在Unity中使用C#更改玩家方向

如果使用C#按下左/右键,我一直试图让这个Object自行前进并以循环方式左转或右转,这张图片将更清晰: http : //prnt.sc/avmxbn 我只能自己移动,这是我的代码到目前为止: using UnityEngine; using System.Collections; public class PlayerBehaviour : MonoBehaviour { Update(){ transform.localPosition += transform.forward *speed *Time.deltaTime float speed = 5.0f; // Use this for initialization void Start () { Debug.Log (“it’s working?”); } // Update is called once per frame void Update () { transform.localPosition += transform.forward * speed * […]

ThirdPersonController碰撞不调用OnTriggerEnter事件

using System.Collections; using System.Collections.Generic; using UnityEngine; public class Test : MonoBehaviour { public Transform target; // Update is called once per frame void Update () { } private void OnTriggerEnter(Collider col) { if (col.gameObject.tag == “Test”) { this.transform.position = target.position; } } } 我有一个ThirdPersonController,我希望它与立方体或圆柱体碰撞。 该脚本附加到ThirdPersonController。 我试图添加到圆柱体或立方体Rigidbody打开/关闭使用重力和Is Kinematic但没有。 它没有参加活动。

如何为Windows更改统一的Game_Data文件夹

我有统一的Windows平台统一项目,我想更改数据文件夹名称,例如: 如果我们制作一个项目并在建造后将其命名为“ TheGame ”,我们将: D:\\…\\TheGame\\TheGame.exe D:\\…\\TheGame\\TheGame_Data\\ 如何将“ TheGame_Data ”重命名为其他内容?

Unity:在JSON上加载图像/ Sprite

我想在json上加载sprite但是如何? 文字显示但不显示图像。 这是加载我的文本数据的JSON代码。 private void myLoadGameData() //LOAD THE DATA { string myfilePath = Path.Combine(Application.streamingAssetsPath, mygameDataFileName); //I THINK THIS IS THE PATH OF THE FILE if (File.Exists(myfilePath)) { string mydataAsJson = File.ReadAllText(myfilePath); // READ THE FILE TSGameData myloadedData = JsonUtility.FromJson(mydataAsJson); // TSGAME DATA IS A ANOTHER SCRIPT THAT HAVE AN ARRAY FOR THE DATA myRoundData = […]

如何在其他协同开始之前先完成协程

嗨我是团结的新手和c#.. 我在同一场景中有两个脚本文件, 文件versionchecker.cs中的1个协程从我的Web服务器获取版本号数据 public string versionURL = “http://localhost/check.php”; IEnumerator GetVersion() { WWW vs_get = new WWW(versionURL); yield return vs_get; if (vs_get.error != null) { connection = 1; } else { currentVersion = vs_get.text; bundleVersion = PlayerSettings.bundleVersion; connection = 0; } } 但是在beginingscreen.cs的另一个文件中,我有一个开始屏幕的协程.. void Start () { if(!isExit) StartCoroutine (BeginningAnimation ()); else StartCoroutine (EndAnimation ()); } […]

协同程序和while循环

我一直在沿着一条路径进行物体移动我从Navmesh Unity3d开始使用我正在使用coroutine,我用while循环控制它,因为我可以显示 public void DrawPath(NavMeshPath pathParameter, GameObject go) { Debug.Log(“path Parameter” + pathParameter.corners.Length); if (agent == null || agent.path == null) { Debug.Log(“Returning”); return; } line.material = matToApplyOnLineRenderer; line.SetWidth(1f, 1f); line.SetVertexCount(pathParameter.corners.Length); allPoints = new Vector3[pathParameter.corners.Length]; for (int i = 0; i 0) { if (index != path.corners.Length – 1) { start = allPoints[index]; index += […]

错误cs1501 unity3d

我在按键时试图让我的角色躲闪,但我一直在犯这个错误 CS1501:方法Dodge’ takes没有重载Dodge’ takes 2个参数 这是躲避脚本的一部分 这是完整的剧本,闪避部分在最后 using UnityEngine; using System.Collections; public class player : MonoBehaviour { public int playerHP; public GUIStyle bigFont; public int attackPlayer; public int defensePlayer; public int speedPlayer; public int atckSpeedPlayer; public int damage; public enum DodgeDirection { Right, Left, Forward, Backward }; public Vector3 dodge = new Vector3(5, 5, 5); […]