Tag: unity3d

检测滑动手势方向

这是我尝试模拟滑动手势的代码,因此当我构建移动设备时,我知道它会起作用。 什么都没有记录,我很困惑为什么它似乎不起作用。 我希望它在控制台中打印出来,我可以刷RTL (从右到左)或LTR (从左到右)。 我不明白我做错了什么。 void Update() { if (Input.GetMouseButtonDown(0)) { startPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); } if (Input.GetMouseButtonUp(0)) { endPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); } if (startPosition != endPosition && startPosition != Vector3.zero && endPosition != Vector3.zero) { float deltaX = endPosition.x – startPosition.x; float deltaY = endPosition.y – startPosition.y; if ((deltaX > 5.0f || deltaX = […]

更有条理的方式来打电话给Coroutines?

在我的代码中,我需要在上一个完成后调用多个Web请求。 例如: void Init() { StartCoroutine(FirstRequest()); } IEnumerator FirstRequest() { www = new WWW(my_url); yield return www; StartCoroutine(SecondRequest()); } IEnumerator SecondRequest() { www = new WWW(my_url); yield return www; } 如果函数体是巨大的,它很容易混淆和混乱,在Javascript中,有Promise,所以我可以这样做: function init() { return validateParams() .then(firstRequest) .then(SecondRequest) .then((result) => { console.log(result) return result }) } 任何人都有一个线索,我应该如何扩展Coroutines,以便我可以有类似的效果?

无法添加脚本组件,因为无法找到脚本类?

昨天我更新了unity5到2018.2.2f1的统一性。 更新2018.2.2f1后未加载Unity脚本。 一旦我尝试播放场景,脚本没有加载,我无法再次添加脚本,它会出现此错误: 无法添加脚本组件“CubeScript”,因为无法找到脚本类。 确保没有编译错误,文件名和类名匹配。

将字节数组从Unity C#传递到C ++插件

我正在尝试将Texture2D(字节数组)中的原始纹理数据传递给非托管C ++代码。 在C#代码中,数组长度约为1.5kk,但在C ++中,“sizeof”总是返回8。 本机方法的C#声明: [DllImport(“LibName”, CallingConvention = CallingConvention.Cdecl)] static extern IntPtr ProcessData(byte[] data); C ++: extern “C” { __declspec(dllexport) void ProcessData(uint8_t *data) { //sizeof(data) is always 8 } } 我究竟做错了什么? 有没有办法在C ++代码中传递数组而无需额外的内存分配?

移动Rigidbody GameObject的正确方法

我刚开始学习Unity。 我尝试使用此脚本进行简单的移动。 前提是,每当有人按’w’时,盒子就会向前移动。 public class PlayerMover : MonoBehaviour { public float speed; private Rigidbody rb; public void Start () { rb = GetComponent(); } public void Update () { bool w = Input.GetButton(“w”); if (w) { Vector3 move = new Vector3(0, 0, 1) * speed; rb.MovePosition(move); Debug.Log(“Moved using w key”); } } } 每当我使用它时,盒子不会在’w’按键上向前移动。 我的代码出了什么问题? […]

来回移动GameObject

我有一个对象,我想要移动到A点,当它到达A点时它应该移动到B点。当它到达B点时它应该移回A点。 我以为我可以使用Vector3.Lerp void Update() { transform.position = Vector3.Lerp(pointA, pointB, speed * Time.deltaTime); } 但是我怎么能回去呢? 是否有一种优雅的方式来实现这一目标? 显然我需要这样的2 Lerps: void Update() { transform.position = Vector3.Lerp(pointA, pointB, speed * Time.deltaTime); // Move up transform.position = Vector3.Lerp(pointB, pointA, speed * Time.deltaTime); // Move down } 有人可以帮帮我吗?

无法在Unity中的Inspector变量中更改数组大小?

据我所知,这是如何设置矢量“大小” public Color[] teamAColors = new Color[4]; 但是当代码运行时,它看起来像这样 我为[4]添加的数字似乎并不重要,大小始终保持为6.我不确定6号码来自哪里,因为我没有设置任何数字。 我甚至试过 public Color[] teamAColors; 然后让我的数组自动填充长度,但这也不会改变6。

从C#中的inheritance类转换数据类型

我试图理解我的团结项目的inheritance,但似乎已经找到了我的设置的限制。 我在写作时感到困惑,因为我仍在学习正确理解C#。 我有一组inheritance的类,它们基于两种不同的行为进行拆分,这样我就有了正确的引用。 然后我需要转换它们,以便我可以访问其中一个类中的方法。 所以我的结构看起来像这样: public class Behaviour : Position { public Handler reference; public Behaviour(int tx, int ty, Handler refer) : base (tx,ty){ reference = refer; } // overload public Behaviour(int tx, int ty) : base (tx,ty){} } public class Behaviour2 : Position { public SettingsHandler reference; public Behaviour2(int tx, int ty, SettingsHandler refer) […]

UnityWebRequest嵌入HTTP基本身份validation的用户+密码数据不适用于Android

下面的代码用于从我们自己的系统中托管的Thingworx服务器获取温度值。 这在团结中非常有效 。 但是在andoird中 ,一旦生成了apk,它就不会从服务器获取任何数据,并且会建立连接。 但是,它只是不会获取数据并将其放入文本网格中。 我正在使用统一5.4.1 32位。 检入Android – 5.0.2和6。 using UnityEngine; using System.Collections; using UnityEngine.Networking; using System.Text.RegularExpressions; using System; using UnityEngine.UI; public class GETTempValue : MonoBehaviour { public GameObject TempText; static string TempValue; void Start() { StartCoroutine(GetText()); } IEnumerator GetText() { Debug.Log(“Inside Coroutine”); while (true) { yield return new WaitForSeconds(5f); string url = […]

安装时将Resources / StreamingAssets中的文件复制到Application.persistentDataPath

我有txt文件,其中包含我在游戏中的地图数据。 问题是文件存储在Application.persistentDataPath所以我甚至可以从我的android设备(创建的地图创建者)更改它,那么如何在我的PC上创建包含基本地图的txt文件并使其显示在我的android上的persistentDataPath我安装应用程序时的设备?