unity5

Unity 2D: PlayerPrefs Implementation for Highscore

本小妞迷上赌 提交于 2019-12-13 03:45:55
问题 I need some assistance implementing a HighScore that saves. Currently, I have a score, which starts from 500,000 and gets down 150 points per seconds. This works, although when I die it still goes on, which I need to fix. I have a second kmHighscore Text, and I want it to show the highscore. Right now it shows the exact score on which I died(for example 450,875), but when I restart the game I can't seem to make it be saved. I tried with PlayerPrefs, but I am not sure how to apply it in my

OnTriggerStay not called every frame

浪子不回头ぞ 提交于 2019-12-13 03:24:02
问题 I have 2 identical GameObjects (crates - prefabs) and 2 spots where that crates need to get. When player push first crate to spot 1, OnTriggerStay in script attached to that crate activate and do the job all time (print in console). Problem is that when second crate get to second spot, it do job 20-30 times (print) and then stop, then I need to just touch it (move a little) and again it does job 20-30 times and stop. Here is script attached to crates: public class Block : MonoBehaviour {

how to translate a sprite for a certain duration using C# unity [duplicate]

烂漫一生 提交于 2019-12-13 02:37:05
问题 This question already has answers here : Move GameObject over time (3 answers) Closed 2 years ago . Generally I know how to translate a sprite to a given position, but how can I translate a sprite to a given position over a time period? 回答1: This has been asked over and over again. Simply searching on Google would have came up with an answer on SO. This can be done with the use of Lerp , Coroutine and Time.deltaTime . The example below will move the Object from postion A to B within 1 second.

Colliding objects bouncing off when isTrigger is true instead of passing through

帅比萌擦擦* 提交于 2019-12-13 02:25:29
问题 I have looped through some game objects to set the isTrigger property before a certain collision occurs but though the property is true collision with the object still occurs. Please see the relevant code below: void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.tag == "object1") { for (int i = 0; i < badGuys.Count; i++) { badGuys[i].getBadGuyGameObject().GetComponent<Collider2D>().isTrigger = true; } } else if (col.gameObject.tag == "object2") { // collision with object1 always

How to I get more reliable Y position tracking for the Google Tango in Unity?

此生再无相见时 提交于 2019-12-13 00:55:13
问题 We have a unity scene that uses arealearning which has been extremely reliable and consistent about XZ position. However we are noticing that sometimes the tango delta camera’s Y position will "jump up" very high in the scene. When we force the tango to relocalize (by covering the sensors for a few seconds), the Y position remains very off. At other times, the Y position varies a 0.5 - 1.5 unity units when we first start up our Unity app on the tango and are holding it in the exact same

Run code when button is held down

喜夏-厌秋 提交于 2019-12-12 20:07:01
问题 I am new to unity and building a game, I use 2 buttons (IncreaseButton, DecreaseButton) the problem I have is that the button callback functions are only called once, when the user clicks on the button but not when the button is held down. How can I make the button to be called repeatedly when held down? Code public void IncreaseBPM() { if (speed < 12) { speed += 0.05f; bpmText.GetComponent<BeatTextControl> ().beats += 1; PlayerPrefs.SetFloat ("savedBPM", speed); } } public void DecreaseBPM()

Properties in c# in Unity (Unity5) - can you avoid the backing variable

旧街凉风 提交于 2019-12-12 11:28:49
问题 With Unity5 (it's hard to know exactly what version of c#/Mono/.Net is being used), we do properties exactly like this: private int _distance; public int Distance { private set { _distance = value; controls.Blahblah(_distance); } get { Debug.Log("hah!); return _distance; } } But consider the new "automatic properties" in c#, which seem to be like public int Distance {get; set;} // ? but I don't know how to "do something" in the getter/setter ?? Or in other words, is there a way to auto

How can i scale a cube to only one direction left?

限于喜欢 提交于 2019-12-12 06:39:48
问题 And then only to right and only to up and only down. The main idea is to scale to one direction. The problem is i'm not using the editor to add new empty gameobject or a cube. I'm using a script to create a cube and a new empty gameobject. In the editor in the scene window i have a cube already. And in the script i'm using this cube to create/duplicate another cube and creating new empty gameobject. I tried to work like the answer here: The solution method 2. Solution But this solution is

Back and forth movement using Rigidbody2D movePosition

[亡魂溺海] 提交于 2019-12-12 05:59:33
问题 I have two force fields I & II (Image here - https://i.stack.imgur.com/yXAhQ.png). They both have an attached script with a bool 'repel', which is toggled on MouseDown(). These force fields need to either attract or repel a spaceship directly in its path. The actual movement of the ship is done by raycasting right & down from the ship. These raycasts check the 'repel' bool of the force fields and the ship is then either moved away or towards the force fields. All gameObjects are Kinematic. I

OnBecomeVisible for Canvas UI Objects

南笙酒味 提交于 2019-12-12 05:41:12
问题 I was searching for method similar to OnBecameVisible for Canvas UI. MonoBehaviour.OnBecameVisible() So that I can load and unload image resources based on requirements. But I can't able to find anything useful in this. I have this kind of page exist which contains 250+ flowers information so I have to manage my texture resources for this. If I disable Image component then page loaded correctly in game otherwise game get crashed in iPhone device when I load this page because of too much