unity5

Location of Application.persistentDataPath in a build

a 夏天 提交于 2019-11-27 14:15:01
When I run my game from the editor and save load data, I find that data in: C:\Users\User\AppData\LocalLow\DefaultCompany\projectname\data . When I build it and get an executable, that data still loads fine, but if I save and restart, it does not get saved. However it does when I launch it from the Editor. Is this a fault in my code or is the files somewhere else when I don't run it from Unity Editor? Later when I export the game to launch it, I have persistent data I Json files that have to come with it for the game to work. For clarity, here is the class that handles save/load of Json:

Move player to exact touch/mouse click location

北慕城南 提交于 2019-11-27 07:22:39
问题 In my 2D unity game, I am trying to move my sprite to the location of my touch/cursor (right now it's a mouse click). My sprite is at the location (173, 48, -52.1). However, when I click a location that is probably a few pixels away my position is changed to (399, 129, 0) and my sprite is apparently hurled into the vast unknown. if (Input.GetMouseButtonDown(0)) { //fingerPos = Input.GetTouch(0).position; fingerPos = Input.mousePosition; transform.position = fingerPos; Debug.Log(transform

Unity 5.3 How to load current level?

只谈情不闲聊 提交于 2019-11-27 06:37:12
问题 before Unity 5.3, I could do Application.LoadLevel(Application.loadedLevel); But now it's something weird with SceneManager. I've read documentation but nothing. How do I get the current scene and load it (Unity 5.3f4)? Thanks! 回答1: Use the new SceneManager and make sure you include the namespace UnityEngine.SceneManagement using UnityEngine.SceneManagement; public class Example { public void ReloadCurrentScene() { // get the current scene name string sceneName = SceneManager.GetActiveScene()

Scale gameobject on just one side

最后都变了- 提交于 2019-11-27 06:26:17
问题 I have added Cube to scene and I scaled and put to position ( 0, 0, 0 ). I am scaling that Cube with code attached to Cube IEnumerator Start() { StartCoroutine("DoSomething", 2.0F); yield return new WaitForSeconds(1); StopCoroutine("DoSomething"); } IEnumerator DoSomething(float someParameter) { while (true) { transform.localScale += new Vector3(0, 0.1f, 0); yield return null; } } but Cube scales on both sides, to top and bottom. I want to scale with same factor but that bottom of Cube stays

How do I sync non-player GameObject properties in UNet/Unity5?

让人想犯罪 __ 提交于 2019-11-27 02:54:59
问题 I'm working on and learning some basics of Unity 5, UNET, and networking. I made a simple 3D game where you go around and change the colors of objects. But I want to make it multiplayer now, and I am having lots of trouble figuring out how to send the changes over the network so all players can see a single player's color change. Part of the issue is that it has been difficult to find the answer using the newer UNET networking engine. And sometimes I come across answers that are for the older

Rotating a gameobject to a specific point [duplicate]

风格不统一 提交于 2019-11-26 23:41:41
问题 This question already has answers here : Rotate GameObject over time (2 answers) Closed 2 years ago . in my project i have a bridge at the moment when i colide with the bridge it rotates and don't stop rotate, what i want is to rotate that bridge trough a specific point and stop rotate, that bridge is inside a gameobject that is my pivotPoint in general i rotate the pivotPoint not the bridge, so i did this: using UnityEngine; using System.Collections; public class fallBridge : MonoBehaviour {

Proper way to move Rigidbody GameObject

自作多情 提交于 2019-11-26 23:07:08
I just started learning Unity. I tried to make a simple box move by using this script. The premise is, whenever someone presses 'w' the box moves forward. public class PlayerMover : MonoBehaviour { public float speed; private Rigidbody rb; public void Start () { rb = GetComponent<Rigidbody>(); } 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"); } } } Whenever I use this, the box doesn't move forward on a 'w' keypress. What is wrong with my code? I thought it might be the way I have

DropDown GUI (resolution) issue Unity 3D

霸气de小男生 提交于 2019-11-26 22:12:38
问题 http://imgur.com/UNR6nNS Check the link for details. When I'm running my app (that contains the DropDown feature) on my Android Phone, the dropdowns that apears from DropDown menu is really small, even tiny. I tried to set resizeTextForBestFit and resizeTextMinSize/maxSize + change Rect.height of ViewPort (where the dropdowns placed) but it doesn't work. The Scroll Rect on Dropdown List controlling the size. So how can I fix this issue? 回答1: Always choose "Screen Space - Overlay" and "Scale

Objects in Scene dark after calling LoadScene/LoadLevel

大憨熊 提交于 2019-11-26 16:48:47
I completed Unity's roll-a-ball tutorial and it works fine. I changed a couple of materials to make it look better. I also added a C# script that should restart the level when the player falls off of the ground (I disables the walls). I am using Unity 5.5. It initially looks like this: But when I go off the edge and the level restarts, it looks like this: It sometimes looks like this for a few seconds after opening unity when the editor is loading. Here is the script: using UnityEngine; using System.Collections; public class DeathTrigger : MonoBehaviour { // Use this for initialization void

Location of Application.persistentDataPath in a build

做~自己de王妃 提交于 2019-11-26 16:38:35
问题 When I run my game from the editor and save load data, I find that data in: C:\Users\User\AppData\LocalLow\DefaultCompany\projectname\data . When I build it and get an executable, that data still loads fine, but if I save and restart, it does not get saved. However it does when I launch it from the Editor. Is this a fault in my code or is the files somewhere else when I don't run it from Unity Editor? Later when I export the game to launch it, I have persistent data I Json files that have to