unity3d

How can I create an alias for a class, globally, in Unity?

为君一笑 提交于 2021-02-05 08:05:16
问题 Right now, I am using "string" to enumerate a list of equipment slots on a character. I am also using "string" to enumerate the class type that the item can be equipped on. This makes all my methods where I get, remove, generate, etc. items involve having two string parameters that is an equipment slot and class type. What I really would like is to use 2 classes so that I have 2 strongly typed concepts for the slot and class_type. The problem is that string is a sealed class and thus I cannot

Moving from one place to another over time (or rotating) in Unity

时间秒杀一切 提交于 2021-02-05 07:48:06
问题 I have a problem with moving from one place to another in Unity over time. I would like my character to move from current position to current + 1 on Y. Unfortunately, looks like it does not get the current position properly or something, since if I debug what I wrote, it says that the magnitude is always 1, so the point is moving with me. Shouldn't it just check the current position and add 1 to Y, move to that position and then check again? I have no idea what's wrong with this code, or if

Access variable from a different scene in Unity

荒凉一梦 提交于 2021-02-05 06:39:12
问题 I am fairly new to Unity and C# and am having some trouble. I am designing a 2d game, which has multiple levels. Each level contains a LevelManager which stores whether the level has been completed or not. They also have the DontDestroyOnLoad command in them. I want to access all the LevelManager gameObjects in my game and then store them in a level select scene. I want to use the win/lose bool to determine if the level has been completed so I can unlock the next level. To be clear, I want a

GetComponent function returning null

天涯浪子 提交于 2021-02-05 06:16:25
问题 I'm developing a simple game in Unity 2017 in C#. In my levels menu I have a Text object with a button component in it, and a script attached to it. This is what's currently in the script: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class LevelLock : MonoBehaviour { public bool isLocked = true; private Button lvlBtn; // Use this for initialization void Start () { lvlBtn = GetComponent<Button> (); if (lvlBtn != null) { Debug.Log (

Accessing object's position from another script in Unity

风流意气都作罢 提交于 2021-02-05 06:10:03
问题 I'm making a game with both a ball and a player. So far I made a sphere for the ball and a square (models will be made later) for the player. I attached a movement script to the player so that it can go in all directions, but I want him to be able to pick up the ball when he runs into it. To do this, I'm assuming that in the ball script, within a collision function, I would have to change its position to the position of the player. So I'm wondering: what is the correct way of accessing those

Accessing object's position from another script in Unity

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-05 06:05:23
问题 I'm making a game with both a ball and a player. So far I made a sphere for the ball and a square (models will be made later) for the player. I attached a movement script to the player so that it can go in all directions, but I want him to be able to pick up the ball when he runs into it. To do this, I'm assuming that in the ball script, within a collision function, I would have to change its position to the position of the player. So I'm wondering: what is the correct way of accessing those

Whats the difference between OnApplicationFocus() and OnApplicationPause()?

徘徊边缘 提交于 2021-02-05 05:47:22
问题 Speaking of mobile devices, whats the difference between those two methods? If I press the home key both are called. Is there any situation when one is called and not the other? 回答1: Since this UnityAnswer is one of the first (if not the first) to be returned on a search for OnApplicationFocus/Pause & iOS, an important update in Unity 4.6.1 has changed the behavior for iOS. As of 4.6.1, both OnApplicationFocus and OnApplicationPause will be called in iOS. The order is : App initially starts:

Whats the difference between OnApplicationFocus() and OnApplicationPause()?

一曲冷凌霜 提交于 2021-02-05 05:46:11
问题 Speaking of mobile devices, whats the difference between those two methods? If I press the home key both are called. Is there any situation when one is called and not the other? 回答1: Since this UnityAnswer is one of the first (if not the first) to be returned on a search for OnApplicationFocus/Pause & iOS, an important update in Unity 4.6.1 has changed the behavior for iOS. As of 4.6.1, both OnApplicationFocus and OnApplicationPause will be called in iOS. The order is : App initially starts:

How to resume game after pressing back in menu

不打扰是莪最后的温柔 提交于 2021-02-05 05:39:46
问题 Hey I am trying to make a pause menu in my game. When escape is pressed pause game go to menu, but now I want to be able to press back in menu and resume my game. So far I can only pause game and cant press back. Also if i press Play in menu it starts at my tutorial scene and not the current scene. Is there a smart way to do this? Without resetting my game. `using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; public class MenuScript : MonoBehaviour { // Use this for

How to resume game after pressing back in menu

两盒软妹~` 提交于 2021-02-05 05:39:45
问题 Hey I am trying to make a pause menu in my game. When escape is pressed pause game go to menu, but now I want to be able to press back in menu and resume my game. So far I can only pause game and cant press back. Also if i press Play in menu it starts at my tutorial scene and not the current scene. Is there a smart way to do this? Without resetting my game. `using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; public class MenuScript : MonoBehaviour { // Use this for