Chris McFarland
  • Member for 10 years, 1 month
  • Last seen more than a month ago
1 answers
17 votes
6k views
Player jittering against wall when held down button
Accepted answer
50 votes

The jittering is happening because you're warping the player into the wall using Transform.Translate, and the physics step is saying, "Hey, we're in the wall. Let's solve this collision issue and push ...

View answer
1 answers
11 votes
9k views
Unity - Order in Z layer for objects
Accepted answer
17 votes

To achieve this effect: Create two sorting layers: Ground and Objects. Have your road, grass, and path sprites use the Ground layer. Have your character, walls, and house sprites use the Objects ...

View answer
2 answers
5 votes
12k views
Updating game objects already placed in scene
Accepted answer
8 votes

When modifying a prefab in the scene, you can save the changes to be reflected on all instances of the prefab by clicking the Apply button in the Inspector tab - children, component values, everything ...

View answer
2 answers
4 votes
5k views
Alternatives to remove Unity splash screen after developing a game with the free version?
Accepted answer
8 votes

According to the Unity store page, the $75/month subscription is locked in for 12 months, so it would cost $900 for one year. (click the $75/month price link for subscription details) If you wanted to ...

View answer
1 answers
5 votes
2k views
Unity2D jumping inconsistancy
Accepted answer
7 votes

I'd recommend changing Input.GetKey("space") to Input.GetKeyDown("space"). This way the check is only performed on the initial key press, rather than every frame the spacebar is held. The other issue ...

View answer
1 answers
5 votes
179 views
Do I need Microsoft authorization to support Xbox 360 controllers for a pc game?
Accepted answer
6 votes

No, you do not need authorization from Microsoft to support Xbox 360 controllers. You can use the XInput API for free.

View answer
1 answers
4 votes
1k views
How are game menus logically structured?
6 votes

As someone who's just spent over a month creating an inventory system, perhaps my menu system can give you some ideas. At its base, you have categories. Within each category, you can have multiple ...

View answer
4 answers
3 votes
11k views
Detect collision from a particular side
Accepted answer
6 votes

You don't have to have only one collider on your character; you can have multiple colliders to perform different checks! I would suggest creating a separate collider that is located on your character'...

View answer
1 answers
2 votes
5k views
What is a faster alternative to a GetComponent from a RaycastHit?
Accepted answer
5 votes

You could use a Dictionary. Store all Transforms as a key with reference to each Car. In this example, we have a god Game class that holds references to all Cars. (just make sure your Script ...

View answer
1 answers
2 votes
2k views
How to load values into a script from a file?
Accepted answer
5 votes

Short of using a third-party parser or writing your own parser for any file format, Unity 5.3 has a built-in JsonUtility class that can automatically parse a JSON string and apply its values to a ...

View answer
1 answers
1 votes
14k views
Switching renderer off/on for an object in unity using C#
Accepted answer
5 votes

gameObject is case-sensitive. If you're using Unity 4.x, you should be able to disable a renderer like so: this.gameObject.renderer.enabled = false; If you're using Unity 5.x, the shortcut to ....

View answer
2 answers
6 votes
35k views
How to ignore collision between two objects
5 votes

You can use Physics.IgnoreCollision and make your projectile ignore your player: http://docs.unity3d.com/ScriptReference/Physics.IgnoreCollision.html Or, you could specify and use 3 different layers: ...

View answer
3 answers
17 votes
4k views
Is Unity 2017 random number generator deterministic across platforms given the same initial seed?
4 votes

Using Unity 2017.2.0f3, UnityEngine.Random appears to give the same results across multiple platforms. Tested on Windows 10, macOS 10.12 Sierra, and Android 7. To test, I trimmed down a SeedFactory ...

View answer
1 answers
0 votes
121 views
Increase speed with each enemy destroyed?
4 votes

Rather than calling GameObject.FindGameObjectsWithTag every frame, you could just call Gunner_SpeedIncrease() within OnTriggerEnter when the trigger/collision happens. void OnTriggerEnter(Collider ...

View answer
1 answers
-2 votes
24 views
how can i take the value of a vector 3 from a liste of vector 3
4 votes

Instead of foreach, you'll want to use for. for (int i = 0; i < position.Count; i++) { Vector3 posit = position[i]; ... } This way, you'll be able to access the previous position using ...

View answer
1 answers
-1 votes
1k views
Error CS1061: doesn't contain a definition for `transfrom' and no extension method `transfrom' of type `PlayerControl' could be found
Accepted answer
3 votes

You have a typo in your code. transfrom should be transform.

View answer
2 answers
13 votes
11k views
Unity UI square that fills width OR height
3 votes

This is possible, but with probably just a small line of code or two for defining whether or not the screen is landscape or portrait and changing a couple values. On the Canvas, you need to make the ...

View answer
1 answers
0 votes
9k views
How to execute code every x seconds in unity?
3 votes

You're on the right track with InvokeRepeating. However, three issues: You're currently calling your invoke method every .01 seconds. Your invoke method disables your myLight component, rather than ...

View answer
1 answers
2 votes
1k views
How should a Unity object control it's state?
3 votes

For states, I usually use Enums, and then do a switch statement within the Update method. Enabling/disabling components is probably easier than adding/removing them. If you need to listen for or be ...

View answer
2 answers
2 votes
612 views
Is it a bad idea to have several audio sources on the same object in unity?
2 votes

While you can have multiple AudioSources on one GameObject, I would recommend creating multiple child GameObjects under one parent GameObject with one AudioSource on each child, because: calling ...

View answer
1 answers
1 votes
2k views
Dragging UI element lags behind the cursor
Accepted answer
2 votes

Your computer is using a hardware cursor, which is extremely fast at rendering the cursor. Unity will be rendering the frame a few milliseconds slower than the cursor. All games have input lag to ...

View answer
1 answers
2 votes
826 views
Unity is reseting Dictionary when game is playing
2 votes

In Unity, Dictionaries are not serialized out of the box, so if they were populated in the Editor, they become cleared when the game starts. You will want to run your AddItemComponent method at ...

View answer
3 answers
-1 votes
189 views
AI: how can i detect if "i am under attack"?
2 votes

As a rough idea: When a bullet hits something, perform a Physics.OverlapSphereNonAlloc call (or if 2D, Physics2D.OverlapCircleNonAlloc) that checks for the layer that your creatures use, using the ...

View answer
2 answers
2 votes
1k views
Enemies are penetrating in each other when following player
Accepted answer
2 votes

To avoid penetration, increase each NavMeshAgent's radius so it's equal to or larger than your agent's collider.

View answer
2 answers
2 votes
1k views
In the Unity Editor, how to push a parent's transform down to its children?
Accepted answer
2 votes

In the Hierarchy tab, you could click-and-drag the child Transforms to a root-level empty Transform. This will keep the children's world position, scale, and rotation, while also keeping them within a ...

View answer
4 answers
1 votes
18k views
How to make switch work with enum? C# Unity
2 votes

Your switch statement is checking _fo.fadeType. Because _fo is private without [SerializeField], it won't show up in Unity's Inspector tab unless you enable Debug mode. Your code has _fo = new ...

View answer
1 answers
1 votes
431 views
Playing multiple sounds in Unity5
Accepted answer
2 votes

Big edit: From chatting and working with Robert on this, to resolve this issue, the solution seems to be: Remove the carSounds = playerCar.GetComponents<AudioClip>(); line because ...

View answer
1 answers
-3 votes
94 views
Does Holacracy help new game development teams?
Accepted answer
2 votes

Try it - or not. There is no recipe for success. Everyone's different. Every team is different. If it works, great! If it doesn't work, then at least you'll learn from the experience.

View answer
1 answers
2 votes
132 views
How can I grab the script component of a collided object without knowing what script it is?
Accepted answer
2 votes

Assuming your Unit class has the health var, try: Unit pirateUnit = collidedObj.GetComponent<Unit>();

View answer
1 answers
1 votes
177 views
Fire an event while the mouse is down within my box 2d collider in Unity
Accepted answer
2 votes

You could use a combination of both OnMouseDown and OnMouseOver: OnMouseOver is called every frame while the mouse is over the GUIElement or Collider. You might want to set something like bool ...

View answer