New answers tagged

0

One possibility would be for the server to enumerate the content it needs to send at the time the download is initiated, and start by sending the player an estimate of the total download size. Ie. "User A is logging in, in game state B. That means I need to send them map X and assets Y and Z. Altogether that makes ## MB of data, so I'll tell them to expect ...


0

I can't comment because I don't have enough rep, but ignore that 'clustering 5/11 jobs' comment. That is unity baking Light Maps and has NOTHING to do with the prefab performance increase you are discussing. I can't comment on Prefab performance, but would like to know if they do help. I hope they do, it seems like it would make sense. Any information you ...


1

This seemed a simple solution: you can use st.Reset() etc as you need in your own code. [SerializeField] private TextMeshProUGUI countDownDisplay; Stopwatch st = new Stopwatch(); void SomeEvent() { st.Start(); } void Update() { if (st.IsRunning) { int secondsUntilDestructSequence = 5; int elaspedSeconds = Mathf.RoundToInt((st....


1

If you don't want collisions to be able to push your objects, you can make them Kinematic (Under Rigidbody 2D -> Body Type -> Kinematic) This tells the Physics engine "I will take responsibility for this object's movement, including dealing with collisions, so you don't have to push this object around to solve penetration" The trick is that then you ...


0

I finally figured out what was going on. It turns out that it only looked like the World GameObjects weren't initialized before the scene was rendered. Each world GameObject has a button whose Target Graphic property is set to a child Text object called DisplayName. This child object displays the world's name(World1, etc.) The button's Fade Duration property ...


0

Your for loop is doing too much work. Here's a version that should do what you want; I'm not convinced it's the right way to do it: Vector3[] vertex_data = new Vector3[f_count]; Vector3[] normal_data = new Vector3[f_count]; Vector2[] texcoord_data = new Vector2[f_count]; int[] triangles = new int[f_count];...


2

When the other script contains the information whether the object is currently rotating or not, then it can also contain the information whether it just stopped rotating. You are not saying how that other script works exactly, but I would assume it determines the state in its update method. In that case you could modify the update method like this: void ...


0

Many good answers but for a more clear picture, here is the picture cause picture tells a thousand words: At your local system, you can effectively utilize PlayerPrefs, DontDestoryOnLoad, Static variable(Data) script, System.IO File handling, or SQLite database (The pros and cons already mentioned in above answer). While you can also use the server-side (...


0

Deleting the EMP folder from the assets folder and reinstalling it seems to put it right.


0

In Text Mesh Pro, you can use overlay shader to render alway on top. And for normal rendering, you can use Distance Field Shader. Here is the demo.


0

You can simply Instantiate the prefab, disable it, modif it, and keep it as a reference. Once you need it, simply call Instantiate on the disabled gameobject, and use the result.


0

This is likely caused by the physics engine updating your character out of sync with the rendering framerate, which is normal. The standard way to avoid this is to turn on interpolation for your player gameobject. Interpolation is perfect if you use a kinematic rigidbody as your player, and a good compromise if you use a dynamic rigidbody. You can also ...


0

It turned out that the GameObject was a child of another GameObject. The parent was rocking back and forth slightly, which created the oscillating movement and apparently overrode and nullified attempts to move the GameObject through rigidbody.position or rigidbody.MovePosition(). I solved the issue by removing the GameObject from its parent and making it a ...


0

I use a functional approach I call Stateless Scenes. I don't like the God class, Singleton, DontDestroyOnLoad or static variables as they all have their quirks. using UnityEngine; public class MySceneBehaviour: MonoBehaviour { private static MySceneParams loadSceneRegister = null; public MySceneParams sceneParams; public static void ...


1

This is my solution, Google Earth like control with smooth animation (or not), when zoomed in it is user friendly and slows panning down. The only thing I am not satisfied about is the quaternion slerp, at these defaults there won't be any sudden jumps but I would have loved to understand how to sub-interpolate quaternions so it works even when rotating ...


0

Here's an alternative approach: scale your mouse delta down if you zoom in and up if you zoom out. Now my math is a bit rusty, so I am not 100% sure, but I think if you just lerp between whatever speed that "looks" right at max and min zoom, you should achieve something that looks right all the way.


1

Avoid placing the camera on the player GameObject at all, unless it's provisional or you really know what you are doing. In most cases most issues are solved if you have an independent camera object (not parented with the player in any shape or form) and use the Update or LateUpdate method to put it into the right position at every frame. Physical effects ...


-1

I was under the impression that anything that happens in the Start() method takes place before GameObjects are rendered. No, here is a link that breakdowns the unity events execution order And also, loading files and loops might take time, a workaround will be to put your buttons under a CanvasGroup component with an alpha of 0 til everything is loaded.


3

The easy solution would be to simply give the object a BoxCollider and a Rigidbody and let the Unity physics engine figure out how it lands. But let's assume you have a good reason why you want to use your own physics and thus want to calculate it yourself. You will have to cheat here a bit, because in many situations there will be two correct solutions. ...


2

No, you should not use deltaTime for this input. Input.GetAxis("MouseX") and ..."MouseY" give you values proportional to the number of pixels the mouse has moved since the last frame So assuming the mouse is moving in one direction over this interval, the values will already naturally be larger on long frames that cover a lot of movement, and smaller on ...


1

The problem appears to be that Unity generates mip maps from your texture without considering the "cell borders" in your textures (how could it at the texture importing stage when it does not yet know how you are going to set up your UV maps?). So the brown parts of the textures bleed into the green parts. A quick and dirty solution would be to turn off mip ...


2

I had the same issue days ago while creating a pong game. The problem was with the Velocity Threshold of the Physics Engine provided by unity. You need to tune it to get a smooth bounciness effect. This is the overall set up (i.e. 1 and 2 is already there in your project) Angular Drag and Drag of the rigidbody2d = 0 Physics2d Material's bounciness = 1 ...


1

This is a conceptual problem, Animations are file assets in the project while GameObject is a reference to something in your active Scene(s). you cannot drag a Scene GameObject in an AnimationEvent but only prefabs. you can have a workaround: by passing a string and doing the lookup ? don't forget some defensive null checks. Having that animation directly ...


1

Turns out, the problem was the boundaries of the box collider attached to the player. As shown in the image below, box collider boundaries (green lines) covered the game objects I thought I was clicking on and that blocked getting the click messages. Once I changed the collider boundaries, the click messages were getting through to the objects. The ...


2

To move a rigidbody, there's a few different tools: If it is not kinematic, use rigidbody.velocity or rigidbody.AddForce. For example rigidbody.velocity = Vector3.forward * Input.GetAxis("Vertical") * playerSpeed; If it is kinematic, use MovePosition: rigidbody.MovePosition(rigidbody.position + Vector3.forward * (Input.GetAxis("Vertical") * playerSpeed * ...


0

Looking at the code you referenced in your link, and the code you wrote, I'm not sure how you came up with that to be honest... Especially the time variable which doesn't exist in the example you posted and what you do to calculate it isn't in the example you posted either... So I'm wondering whether I'm understanding your question correctly or whether you ...


0

The problem with the configuration is the negative spacing. The negative spacing exceeds the width of a card, and the card slides all the way back to the left side as a result. To fix it, the spacing should be set to a value which is greater than -50 units.


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

Cameras are very sensible to anything that does not move them perfectly smoothly. The camera should be updated in an Update or LateUpdate. One way to handle cameras is to adjust variables in a FixedUpdate, and to move the camera in the (Late)Update based on the given variables. Moving the player in a FixedUpdate with the camera being parented to will cause ...


0

I found the issue! I was looking into the error messages and found a similar post on the unity forums. --https://forum.unity.com/threads/visual-studio-tools-tab-dont-show-and-cant-attach-to-unity.365416/ One of the people said that there are issues if you have multiple versions of unity or multiple versions of visual studios. I found a few things about ...


2

You don’t. This would need to be simply a single-step achievement.


0

In the top right (I believe that is the default), there is a section called transformation. You can change those numbers to all 0. I believe there is also an option to 'reset' as well in the transform section.


1

It's spelled Rigidbody2D, not RigidBody2D. Capitalization matters in C#.


2

A very simple way to control the speed of a Unity game is by changing the value of Time.timeScale. The default value is 1, and higher values mean higher speed. 2 means twice as fast, 0.5 means half as fast, etc.. But keep in mind that this speeds up everything in your game. Often there are various things you do not want to speed up while the game progresses. ...


1

Select an object you want to center your view on and press the F key to snap your scene view camera to that object, zoomed to fit it in view. "Frame Selected" is the name of this shortcut.


0

Uhm, maybe do an if()-clause around the part where you update its force? Btw. that's as far as ANYONE will be able to help you with the information provided. Edit: If your ground is perfectly flat this if could simply check if the y-position is 0, if not you could use some sort of collider for this, but there are probably more (computationally) efficient ...


1

I have found the answer here. Although it is not completely explained mathematically in my opinion, it works well. The code I use is like this: private void Start() { // ... PositionCamera(); } /// <summary> /// Source: https://forum.unity.com/threads/dynamic-loaded-object-fit-to-screen-size.349794/ /// </summary> void PositionCamera()...


0

After the advent of the Asset Bundle Browser tool many things have become easy. Like you can get the dependency of the asset or you can manually drag and drop the asset in asset bundle.


2

You know what? I will be generous. Here is a a script made by unity that pretty much does this for you. Enjoy. using System.Collections.Generic; using UnityEngine; namespace UnityEngine.Rendering { [HelpURL(Documentation.baseURL + Documentation.version + Documentation.subURL + "Free-Camera" + Documentation.endURL)] [ExecuteAlways] public class ...


1

Figured out how to do it. I had to create a new assembly definition in my Scripts folder. (I also moved my Tests folder out of the Scripts folder to be on the safe side.) Then, looking at the Tests assembly definition in the Inspector, I added a new item to the Assembly Definition References list, which I made point to my MainAssembly.


1

What I’m describing was caused by the Rigidbody2D auto-calculate mass. Just uncheck that box and it should work fine!


0

I gave this issue another shot, and I found a solution! I figure that this will probably be helpful to someone in the future, so I will describe exactly how I did it, I will provide minimal code though, because my solutions code is a tiny bit implementation specific. Credit Where it is Due This answer was made possible by this answer here. In fact, my ...


1

As this question is kinda 2 questions in one, I'm going to answer the one that I think is the root of your problem (scale sphere relative to plane). Because if I read this correctly, the pixel part sounds like you only want to do that because you couldn't find the solution to your original problem. In Unity, a position is based on 'units'. a 'unit' doesn't ...


4

You can use the official Unity Recorder asset. The latest Unity Recorder is available in Preview via the Package Manager from Unity 2018.3+, the asset store version is no longer being updated actively I believe.


0

You can possibly achieve tile animation by using unity's "AnimatedTile" Script which comes with the 2d-Extra repo. This video from unity discusses how to use the AnimatedTile Script. I hope it helps. https://github.com/Unity-Technologies/2d-extras/tree/4eff73f468142907629f09b4a88bceb2f0148dc5/Runtime/Tiles/AnimatedTile


6

Unity projects don’t include the source file in the project when building. Instead, every image is converted during import to a format useful to the GPU, as set by you in the import settings for that image. These tend to be larger, especially if an uncompressed format is chosen, and especially if the source image is in a compressed format (eg. jpeg, or png ...


0

It looks like it is not possible to exclude individual assets apart from scripts. To exclude a script you can try following this advice: https://support.unity3d.com/hc/en-us/articles/208456906-Excluding-Scripts-and-Assets-from-builds #if (UNITY_EDITOR) ... your class/code ... #endif To exclude a directory (of scripts) which I assume also works with other ...


1

When the canvas is set to screen space overlay, the z isn't going to do anything as 'Screen space overlay' uses an orthographic camera which renders everything between z -1000 and z 1000 the same. It is not going to look like it is closer to the camera. That is just how an orthographic projection works.. I think you'd either want to set it to Screen space ...


1

There's no Unity-specific jargon for this, because what you're describing is not the engine's job. That's part of your game, which means it's on you to implement this. A rough outline of how this would work: You'd make a data container script representing a "Hoverable" object. You'd place an instance of this component on each object that you want to be ...


1

If your agents are always oriented vertically, this is reasonably straightforward. Just project your velocity into the horizontal plane, and look toward that. This can always be accomplished with a pure yaw, no pitch/roll required: var projected = Agent.velocity; projected.y = 0f; if(!Mathf.Approximately(projected.sqrMagnitude, 0f)) transform....


Top 50 recent answers are included