Tag Info

New answers tagged

0

To disable collision between specific layers you should go to in Edit->Project Settings->Physics and customize the collision matrix, which specifies for each layer combination if they can collide or not. See documentation, hope it helps. If it isn't happening yet, then reasons could be just because you use OnCollisionEnter2D instead of OnTriggerEnter2D() ...


3

As Jinbom said the main difference here is speed. However it is important to note that this is only the case for the transform property of GameObject. Other properties such as camera and rigidbody are just convenience properties and call GetComponent<> under the hood so the performance is identical. It is for this reason that Unity has deprected these ...


5

The Speed (fast to slow): cached _transform >> Component.transform >> Component.GetComponent<Transform> And If you disassemble a UnityEngine.dll C# binary, you can see transform do not call GetComponent (Component class member), just call internal mono runtime method. Here is the transform code. // UnityEngine.Component public Transform ...


1

Right now you can assume that every game object will have the Transform component due to the this.transform syntax. My guess is that Unity updated its API with the GetComponent<>() syntax was so that in the future you could have GameObjects without "special" components like Transform. Then you can have a "purer" architecture where your GameObjects ...


4

Here are the steps for applying scripts to multiple objects. Step 1. Select all your objects from Hierarchy panel. Step 2. Then from Project panel drag & drop your script into Inspector panel.


2

You can add script at runtime. You can create an empty objects with a script that "browse" the 200 or more objects and atach the sript to each of them AtachScriptAtRunTime Example: to add the script named FoobarScript to the game object use: gameObject.AddComponent ("FoobarScript"); Clearly you must recognize all the objects. (example you can use ...


2

That's not using GetComponent() on the class GameObject, it's using GetComponent() on the result of GameObject.Find() GameObject.Find() is a static function, but it returns a specific object. Note that Code 2 is also using GameObject.Find() but then you store the result object in a variable. Code 1 uses the exact same functions but doesn't store the result ...


3

Your LevelCollider is attached to a Collider that is a trigger. That means it will not call OnCollisionEnter. It will call OnTriggerEnter. Try adding this to LevelCollider: void OnTriggerEnter(Collider other) { Application.LoadLevel("Level1"); } That should do ya!


2

Detect collisions with OnCollisionEnter then load your level there. I.e.: void OnCollisionEnter (Collision col) { Application.LoadLevel("Level1"); } If your character's Collider is a trigger, then you need to use OnTriggerEnter. I.e.: void OnTriggerEnter (Collider other) { Application.LoadLevel("Level1"); } If neither of these work, try ...


0

It's not a good idea to dispose/destroy your objects unless you want to change your screen (for example moving from menu to game level ) because when your are disposing/destroying objects , garbage collector is called ,so it's better to store your dead objects in memory instead of destroying them. First off all read this article ...


1

http://en.wikipedia.org/wiki/Flyweight_pattern is the pattern name if I'm reading your question correctly.


2

After some more testing, it appears the problem was the Start() method. Apparently, for whatever reason, the code was being executed as follows: orbControl instantiated -> SetDirection() -> Start() Thus, because of this, direction remained 0. So, I changed Start() to Awake(), and all's well. It appears to me after more research that this is the main ...


0

Drop in a couple breakpoints and see if either of the MoveHandler condition blocks are actually visited in the following code : if(MoveHandler.facingRight) -> orbControl.SetDirection(BasicAttackOrb.RIGHT); else if (!MoveHandler.facingRight) -> orbControl.SetDirection(BasicAttackOrb.LEFT); Since those lines are responsible for changing the ...


1

I assume you assign a Prefab to public GameObject missile in the inspector. When you try to destroy missile inside of your OnTriggerEnter2D method, the error message does make sense, since you're trying to destroy a prefab and not an instance. Instead of trying to destroy missile, you should destroy the object that collided with your GameObject. So, ...


0

You can add a box collider (Add -> Physics -> Box Collider) in the inspector. Then, add a script with a function OnCollisionEnter(Collision other) then add that script to the cube you want to collide with. More info in here: https://unity3d.com/learn/tutorials/modules/beginner/physics/colliders-as-triggers


0

The command to load a level is Application.LoadLevel(). Call that from an "On Collision" function on the cube.



Top 50 recent answers are included