6

Games typically approach this type of issue using a transformation hierarchy. In this model, each entity can be treated as a "child" of a "parent" entity. The entity's local position and orientation components are interpreted to be relative to the position and orientation of the parent. Parent entities may in turn have their own parents, grandparents, etc.,...


5

The reason you wouldn't put the initialize logic in the constructor is because Initialize is the first point where you can be sure that GraphicsDevice is set up. Recall that, while your constructor for your Game-derived class may create GraphicsDeviceManager, the graphics device itself is only created when Game.Run() is called (an instance method, so it ...


3

The documentation you link covers the answer to this, quite clearly. GetComponentsInChildren will return components from all sub children. This is the API reference you link, emphasis mine: Description Returns all components of Type type in the GameObject or any of its children. The search for components is carried out recursively on child objects, ...


3

You'd do this in the opposite order. Rather than: Create Modify Attach to GameObject (there's no way provided to do this) the order is: Create and attach to GameObject (one fused step) Modify Like so: GameObject go = new GameObject(); MeshRenderer newmeshrenderer = go.AddComponent<MeshRenderer>(); // Do stuff with newmeshrenderer, eg... ...


2

I've got a big, somewhat controversial discussion over here about why Game Components are "bad". The most annoying thing about GameComponent, for me, is that it looks really important. It looks like a first-class part of the XNA API - like Vector3 or SoundEffect - but they're actually not (everything in the Game assembly is technically optional). So many ...


2

In comments, I posted a condensed version of my answer old answer: Using DrawableGameComponent locks you into a single set of method signatures and a specific retained data model. These are typically the wrong choice initially, and the lock-in significantly hinders the evolution of the code the future. Here I shall attempt to illustrate why this is the ...


2

It should work like the example on the Scripting API for AddComponent http://docs.unity3d.com/ScriptReference/GameObject.AddComponent.html MeshRenderer mr = gameObject.AddComponent("MeshRenderer"); (...) //do stuff with mr


2

I notice that you're instantiating a new MsgBox instance and then immediately trying to use its members. At this point, all you can guarantee has run are its Awake() and OnEnable() methods (in that order). Start() is called just before its first Update(), which won't happen until after the function that spawns it has returned (or yielded). Since Start() ...


2

As mentioned in a comment above, you can't enable or disable individual points in the LineRenderer. But, you can change/add/remove points dynamically, which can get a similar effect. Here's a sample script that builds a random zig-zag path by adding segments to the end of the line, then progressively chops the line back until it disappears completely. [...


1

Usually I just create a class for that specific form. Using your example login dialog above, that might look something like this: [System.Serializable] public class LoginDialogEvent : UnityEvent<string, string> {} public class LoginDialog : MonoBehaviour { [SerializeField] private InputField username; [SerializeField] private InputField ...


1

I found what i did wrong , It was because I used transform to position a Object that had a rigid body. The RigidBody component causes the object to be subject to Physics Laws and trying to reposition it using transform didn't stop factor like gravity acting on it.


1

var Obehaviour = other.gameObject.transform.parent.gameObject.GetComponent<UnitBehaviour>().Health; <--- Error is here. There are 3 reasons why this line could throw a NRE: other is null other doesn't have a parent the parent gameObject doesn't have a UnitBehaviour Keep in mind that when you put this code snippet into some event handler (I ...


1

This has nothing to do with the tag that you are using. For dropdown fields, the text of the label is overwritten by the dropdown component based on the selected option. In order to set the text of that label, you should go to the dropdown component and set the text of the selected option (Option A) like so: Or unlink the Label from the dropdown component, ...


1

This may help a bit. As for knowing how to do what you exactly want to do, I would need hours of trial and error as I am also a bit of a beginner. public void create() { gestureDetector = new GestureDetector(HALF_TAP_SQUARE_SIZE, TAP_COUNT_INTERVAL, LONG_PRESS_DURATION, MAX_FLING_DELAY, new GestureHandler()); Gdx.input....


Only top voted, non community-wiki answers of a minimum length are eligible