unity5

PlayerPrefs Not working

谁说胖子不能爱 提交于 2019-12-12 05:38:32
问题 Hey so im trying out unitys Playerprefs method and some how it wont save coins and when i close and exit the game it wont save it... public Text CoinsText; public int Coins; public int clicks; void Start() { PlayerPrefs.GetInt("Coins", Coins); } void Update() { CoinsText.text = "Memes: " + Coins; if (Input.GetMouseButtonDown(0)) { PlayerPrefs.SetInt("Coins", Coins); Coins += clicks; } } } 回答1: You're never assigning to your Coins. Try this in your Start(): Coins = PlayerPrefs.GetInt("Coins");

How can I get VideoPlayer source dimensions (width/height)?

霸气de小男生 提交于 2019-12-12 05:29:00
问题 I'm using Unity's new (as of ~5.6.x) Video Player component to programmatically load a video file and play it. But I'd like to be able to detect the dimensions of the source video so that I can resize the render texture target as well as a GameObject containing a control bar for the video. Is there any way to access these properties? Currently, I can see it's possible to get the number of frames, etc, which makes me thing I should be able to get the video's dimensions as well, but nothing I

How can i click and drag a gameobject with the mouse?

北城余情 提交于 2019-12-12 04:24:59
问题 Created new script using System.Collections; using System.Collections.Generic; using UnityEngine; public class mouseDrag : MonoBehaviour { float distance = 10; void OnMouseDrag() { Vector3 mousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance); Vector3 objPosition = Camera.main.ScreenToWorldPoint(mousePosition); transform.position = objPosition; } } Then in another script in the Start function i'm creating 4 cubes and add the mouseDrag to each cube. But when

How to add a Animator Controller to a character at runtime?

若如初见. 提交于 2019-12-12 04:18:54
问题 I have an Animator controller at "Assets/Resources/System/PLController". I have to add it at runtime using a script. How to accomplish this. Using Unity 5 (5.3.0f4) PLController = (Animator Controller) 回答1: First attach an Animator component to that GameObject like Declare an Animator variable. Assign variable through GetComponent Assign RuntimeAnimatorController to its runtimeAnimatorController attribute. Like, Animator PLAnimator; void Start () { PLAnimator = GetComponent<Animator> ();

Make pixel lighting like terraria and starbound

旧街凉风 提交于 2019-12-12 03:54:19
问题 I'm making a 2D sandbox game like "Terraria" and "Starbound". This is my game The light is filling the whole terrain but i don't want it. I want following: 回答1: You're probably using Directional Lighting, which illuminates the whole terrain equally in the direction you made it. You could use Spot Lights or Point Lights, which will illuminate only the surface you want to. Edit: although using this method, this could take way more resources due to the number of single lights placed throughout

Text not adjusting properly on Canvas? [closed]

不羁的心 提交于 2019-12-12 03:28:48
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I want to to achieve this effect. 回答1: Make sure you have the Rect transform tool selected (press T while Scene view has focus). This will correctly display the bounds of your selected UI element. Also, what you are changing in your video is the anchor mode, NOT the text alignment. You can edit that in the Text

How can I detect if a gameObject has collided with two other specific objects at the same time?

别等时光非礼了梦想. 提交于 2019-12-12 03:28:25
问题 How can I detect if a gameObject has collided with two other specific objects at the same time? This is what I intend to do but it does not work: void OnCollisionEnter (Collision col) { if(col.gameObject.name == "object1" && "object2") { Destroy(gameObject); } } How can I correct this piece of code? 回答1: If you are colliding with 2 objects the method OnCollisionEnter will be called twice, so you must keep track of their gameobject or names. List<string> contacts = new List<string>(); void

UI Canvas Start - Quit Game

a 夏天 提交于 2019-12-12 03:25:20
问题 I have 2 Canvas UIs (Start and Exit) on the home screen of my game. I want to add 1 script that does the following: When the UI Image Play is clicked public void NextLevel(int level) { Score.Inicializar(); Application.LoadLevel (1); } When the UI Image Exit is clicked Application.Quit () ; C# if possible. 回答1: Add this script to your Play image: using UnityEngine; using UnityEngine.EventSystems; //using UnityEngine.SceneManagement; // uncomment this line in case you wanna use SceneManager

How to find index of colliding Game Object in OnCollisionEnter2D()

…衆ロ難τιáo~ 提交于 2019-12-12 02:53:23
问题 I have created a prefab and instantiated it a number of times in a script that it attached to another game object as below. void Start () { badGuys= new List<GameObject> (); int numberOfBadGuys = 6; Camera camera = GameObject.FindGameObjectWithTag ("MainCamera").GetComponent<Camera> (); for (int i = 1; i < numberOfBadGuys + 1; i++) { GameObject badGuyObject = (GameObject)Instantiate(badGuy, new Vector3(Screen.width*i/2, Screen.height*i/6, camera.nearClipPlane ), Quaternion.identity ); badGuys

Use assembly class without the assembly object

前提是你 提交于 2019-12-12 02:18:32
问题 I currently load C# code which I have compiled into a DLL using the Assembly class: private void LoadAssembly() { try { Assembly loadedAssembly = Assembly.LoadFrom("E:/MyUtilities/bin/Debug/MyUtilities.dll"); System.Type type = loadedAssembly.GetType("DLLTest.MyUtilities"); FieldInfo field = type.GetField("c"); Debug.Log(field.GetValue(null)); } catch (System.Exception e) { Debug.Log( e.ToString() ); } } This is in a Unity game. It works fine. But I want to load the class into the loading