Tag Info

New answers tagged

0

For the gameObject to always stay in the corner set it's position to camera.ScreenToWorldPoint(new Vector3(0, 0, -camera.gameobject.transform.position.z)) - new Vector3(yourObjectsizeX / 2, yourObjectsizeY / 2,0) [this to make sure the whole button is visible] Regarding the scaling, I did a while back such a scale to the background by defining the width and ...


2

Use the unit test framework 'Unit Test Tools' provided by Unity. You're right you can't create new MonoBehaviours on their own, but why not use an empty GameObject and use AddComponent<MyMonoBehaviour>() and then run your tests? Alternatively you can create the bulk of your logic inside your own classes. Then your MonoBehaviour scripts will just use ...


1

Have a look at IUnified (http://u3d.as/content/wounded-wolf/iunified/5H1), which lets you expose interfaces in the editor, just like you mention. There is a little bit more wiring up to do compared to normal variable declaration, that's all. public interface IPinballValue{ void Add(int value); } [System.Serializable] public class IPinballValueContainer ...


0

I use a few different strategies to get around the limitations you mention. One of those that I don't see mentioned is using a MonoBehavior that exposes access to the different implementations of a given interface. For example, I have an interface that defines how Raycasts are implemented named IRaycastStrategy public interface IRaycastStrategy { bool ...


5

I personally NEVER use SendMessage. There's still a dependency between your components with SendMessage, it's just very poorly shown and easy to break. Using interfaces and/or delegates really removes the need to use SendMessage ever( which is slower, although that shouldn't be a concern until it needs to be ). ...


4

A Unity-specific approach that occurs to me would be to initially GetComponents<MonoBehaviour>() to get a list of scripts, and then cast those scripts into private variables for the specific interfaces. You'd want to do this in Start() on the dependency injector script. Something like: MonoBehaviour[] list = GetComponents<MonoBehaviour>(); for ...


9

There are a few ways you can work to avoid tight script coupling. Internal to Unity is a SendMessage function that when targetted at a Monobehaviour's GameObject sends that message to everything on the game object. So you might have something like this in your health object: [SerializeField] private int _currentHealth; public int currentHealth { get { ...


3

From my own experience, game dev traditionally involves a more pragmatic approach than industrial dev (with less abstraction layers). Partly because you want to favour performance over maintainability, and also because you're less likely to reuse your code in other contexts (there's usually an strong intrinsic coupling between the graphics and the game ...



Top 50 recent answers are included