Tag: unity3d

Unity的安装数据库(SQLite)

我看过太多教程列表,他们都推荐相同的东西。 但是,他们没有帮助解决我的问题。 我试图在我的项目中包含一个SQLite数据库,当构建PC,MAC和Linux Standalone(在Windows机器上测试)时,数据库按预期工作。 在Android设备上进行测试时,出现以下错误。 E/Unity: ArgumentException: Invalid ConnectionString format for parameter “/storage/emulated/0/Android/data/com.tbltools.tbl_project/files/TBLDatabase.db” at Mono.Data.Sqlite.SqliteConnection.ParseConnectionString (System.String connectionString) [0x00000] in :0 at Mono.Data.Sqlite.SqliteConnection.Open () [0x00000] in :0 at UIHandler+c__Iterator2.MoveNext () [0x00000] in :0 at UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) [0x00000] in :0 我认为对connectionString进行修改应该很简单,但这并没有解决我的问题。 这是我到目前为止: if (Application.platform != RuntimePlatform.Android) { // The name of the db. tblDatabase […]

无法通过脚本更改GameObject颜色?

我有一个用于UI的canvas,其图像与canvas大小相同。 Image的rgba为0,0,0,0 ,使其不可见(因为a为0)。 我希望从脚本中将图像淡入黑色。 这是我正在使用的代码: public class NavigationC : MonoBehaviour { public Image screen; float fadeTime = 3f; Color colorToFadeTo; void StartGame() { colorToFadeTo = new Color(0f, 0f, 0f, 255f); screen.CrossFadeColor(colorToFadeTo, fadeTime, true, true); } } 现在,这在执行时没有做任何事情。 但是当我以单位手动更改图像的值以使图像变得可见时,我可以看到脚本改变了图像的颜色。 因此脚本确实有效,它只是不可见,因为脚本没有更改a值。 那么如何让图像从隐形变为黑色呢?

Unity:实时video流

我正在尝试将实时video从一个应用流式传输到另一个应用,目前我有2个应用。 app 1是服务器/发送者,app 2是客户端/接收者。 在app 1中,我成功将video字节发送到客户端。 在客户端,我也收到所有字节。 我使用套接字和TCP。 我面临的问题是,当我收到video字节并将它们分配给原始图像纹理时,纹理上的图像看起来放大太多并且它是如此像素化。 更新的图像 这就是我的流 这就是我在客户端得到的。 这是第一个问题,但我目前正在测试从桌面到另一个,我的目标是将IPAD流式传输到桌面,当我这样做时它很慢并且它会杀死ipad和桌面上的应用程序。 我到目前为止尝试了一些故障 1:我认为这是发生的,因为我有2种不同的分辨率,因为我从ipad流向桌面 2:纹理图像太大,我输出它并返回630.我尝试使用Unity Texture2D.resizeresize但我得到一个灰色纹理,因为该函数将像素设置为未识别 3:我使用其他库来调整纹理大小,我确实得到了我想要的东西,但在12帧之后,rawimage开始在video和“?”之间闪烁。 纹理那么多,然后冻结在两个应用程序(iPad和桌面) 4:我相信我正在阅读纹理的方式导致问题,因为我使用Setpixels和Getpixels函数,它们很重。 我的代码:服务器/发件人方: using UnityEngine; using System.Collections; using System.IO; using UnityEngine.UI; using System; using System.Text; using System.Net; using System.Net.Sockets; using System.Threading; using System.Collections.Generic; public class Connecting : MonoBehaviour { WebCamTexture webCam; public RawImage myImage; Texture2D currentTexture; private […]

Unity – 检查播放器是否接地不工作

我希望玩家在玩家停飞时跳跃。 private void OnTriggerStay(Collider other) { if(other.gameObject.layer == 8) { isGrounded = true; }else { isGrounded = false; } } 产卵时,播放器播出。 在玩家跌落到具有标记Ground的Terrain之后, isGrounded仍然是假的。 当我手动设置isGrounded并再次跳转时,它在碰撞后仍然是真的。 我也不希望玩家在空中双跳,我可能已编码但由于出了问题而无法正常工作。 将OnTriggerStay更改为OnTriggerEnter不会更改某些内容。 我希望你能帮助我。

将旧的Unity代码升级到Unity 5

在触发按钮上播放动画的代码似乎不起作用。 我在Youtube上看到了一个video,并带有一个简单的animation.Play(); 它适用于那个video但是,我无法让它在我的电脑上工作。 我做错了什么或团结改变了什么? 请帮助我无法在网上找到解决方案。 所有“解决方案都不起作用”。 这是我得到的错误: 类型UnityEngine.Component不包含播放定义,也没有扩展方法可以找到UnityEngine.component类型的Play using System.Collections; using System.Collections.Generic; using UnityEngine; public class animationtrigger : MonoBehaviour { void Start() { } int speed = 10; // Update is called once per frame void Update () { if (Input.GetKeyDown(“N”)) { animation.Play(“Cube|moving side”); //transform.Translate(1 * Vector3.forward * Time.deltaTime * speed); //Animator anim = GetComponent(); […]

Unity中的简单套接字服务器

我想在Unity项目中使用C#插件。 该插件应该充当服务器,它将从客户端获取值,以便我能够使用这些值进行进一步处理。 问题是服务器有无限循环。 无限循环导致Unity挂起。 怎么办呢? 编辑:我附加了服务器程序的代码片段。 在我看来,有两点可能导致问题。 无限循环和程序暂停的点,如代码所示: void networkCode() { // Data buffer for incoming data. byte[] bytes = new Byte[1024]; // Establish the local endpoint for the socket. // Dns.GetHostName returns the name of the // host running the application. IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName()); IPAddress ipAddress = ipHostInfo.AddressList[0]; IPEndPoint localEndPoint = new IPEndPoint(ipAddress, […]

Unity – 只需在协同程序完成后才能返回值

我正在进行团结游戏并遇到一个我无法解决的问题。 我通过标准的WWW对象连接到Web服务器并使用协程来执行POST请求。 代码本身可以工作,但我需要更新变量值并在协程完成后返回该变量,这是我无法做到的。 public int POST(string username, string passw) { WWWForm form = new WWWForm(); form.AddField(“usr”, username); form.AddField(“pass”, passw); WWW www = new WWW(url, form); StartCoroutine(WaitForRequest(www)); //problem is here ! return success_fail; } private IEnumerator WaitForRequest(WWW www) { yield return www; if (www.error == null) { if(www.text.Contains(“user exists”)) { success_fail = 2; } else { […]

如何通过GetComponent从另一个游戏对象中的另一个脚本访问变量?

我四处寻找,我无法让它发挥作用。 我想我只是不知道正确的语法,或者只是不完全掌握上下文。 我有一个BombDrop脚本,它包含一个public int。 我使用public static工作,但有人说这是一个非常糟糕的编程习惯,我应该学习封装。 这是我写的: BombDrop脚本: public class BombDrop : MonoBehaviour { public GameObject BombPrefab; //Bombs that the player can drop public int maxBombs = 1; // Update is called once per frame void Update () { if (Input.GetKeyDown(KeyCode.Space)){ if(maxBombs > 0){ DropBomb(); //telling in console current bombs Debug.Log(“maxBombs = ” + maxBombs); […]

在streamingAssetsPath上读写文件

这是我在android中读取我的文本文件的方式。 #if UNITY_ANDROID string full_path = string.Format(“{0}/{1}”,Application.streamingAssetsPath, path_with_extention_under_streaming_assets_folder); // Android only use WWW to read file WWW reader = new WWW(full_path); while (!reader.isDone){} json = reader.text; // PK Debug 2017.12.11 Debug.Log(json); #endif 这就是我从pc上读取我的文本文件的方法。 #if UNITY_STANDALONE string full_path = string.Format(“{0}/{1}”, Application.streamingAssetsPath, path_with_extention_under_streaming_assets_folder); StreamReader reader = new StreamReader(full_path); json = reader.ReadToEnd().Trim(); reader.Close(); #endif 现在我的问题是我不知道如何在移动设备上编写文件因为我在独立版上这样做 #if UNITY_STANDALONE StreamWriter […]

如何从Unity连接到数据库

我试图通过Unity连接到MS SQL数据库。 但是,当我尝试打开连接时,我收到IOException:连接丢失。 我从Unity \ Editor \ Data \ Mono \ lib \ mono \ 2.0导入了System.Data.dll。 我使用以下代码: using UnityEngine; using System.Collections; using System.Data.Sql; using System.Data.SqlClient; public class SQL_Controller : MonoBehaviour { string conString = “Server=myaddress.com,port;” + “Database=databasename;” + “User ID=username;” + “Password=password;”; public string GetStringFromSQL() { LoadConfig(); string result = “”; SqlConnection connection = new […]