New answers tagged

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....


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 ...


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

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 ...


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.


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 ...


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 ...


1

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


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.


1

I was expecting that it was trivial to seed the javascript pseudo-random number generator. Turns out you can't, at least not in any standard portable way. Alright, we are going to implement one. The following is mulberry32 in JavaScript: function mulberry32(a) { return function() { a |= 0; a = a + 0x6D2B79F5 | 0; var t = Math.imul(a ^ a >...


0

Your first problem doing this would be with JavaScript. It doesn't really have a deterministic, seedable random number generator. (Deterministic means it produces the same array of values every time you use it given the same starting conditions, seedable means you can set those starting conditions). C# does have this, when you create a new Random object you ...


1

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


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 ...


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 ...


3

A possible explanation could be that you set FirePoint to something in the inspector before you added the [HideInInspector] attribute. Adding that attribute makes it impossible to change the inspector value, but if there is already one set it won't get cleared. If GameObject.Find("FirePoint").transform throws a NullReferenceException, then that method gets ...


0

You find the basic trigonometric functions in the class Mathf. If you want something to move in a trigonometric function over time, you just need to feed the current Time.time into the function. For example, if you want an object to oscillate on the y axis in a sine curve, you would add this behaviour: using UnityEngine; public class SineMovementBehaviour ...


1

Does it have to be a child object? If not; Create another object. Get a transform reference to it. Update its transform each frame like so; object.position = new Vector2(transform.position.x, object.position.y);


3

Your loop condition is while (n < 1). Since n is integer and initialized to IList<T>.Count, which – on a good implementation – can't be negative. It means that the only value of n that satisfies the condition (n < 1) is 0. That means that it will only enter the loop when the list is empty (n = 0). And in that case there is nothing to shuffle, ...


1

Since you are already parenting the prefabs when you set localPosition that is relative to the center point of the canvas. Change your Start method like this: void Start() { Transform p = GameObject.Find("Canvas").transform; for (int i = 1; i <= N; ++i) { for (int j = 1; j <= M; ++j) { GameObject g = ...


1

using UnityEngine; public class Script : MonoBehaviour { public static int X, Y; [System.Serializable] public class Column { public bool[] rows = new bool[Y]; } public Column[] columns = new Column[X]; } using UnityEngine; using UnityEditor; [CustomEditor(typeof(Script))] public class CustomScriptInscpector : Editor { ...


1

You just have to make the other characters do exactly the same things the player-character does, but with a delay. So you have to create a script which records the actions of the player and then allows to retrieve the player's position X steps ago. The C# standard already has the ideal data-structure for that, the Queue. It allows you to create a first-in-...


3

Are you sure that Unity Tools for Game Dev is unavailabe in VS Community? It should come with the Unity install file but can also be found from the Visual Studio Installer. Also it would help if you stated which version of Unity, Visual Studio and Visual Studio Code you are using. Regardless this link shows the supported IDE's for Unity: https://docs....


0

I figured it out! The problem was when there was a cache hit for vertex 8 in the behindLayer array, it didn't update currentLayer so then when vertex 11 checked if there was a cached index for vertex 8 in currentLayer, it didnt find out and created its own vertex.


1

By default, when new SpecialAttack() is called, before the SpecialAttack() constructor is hit, parent constructors are hit. The language lets you omit/ignore typing the explicit call to the constructor, but that's only for no-arg () constructors. Behind the scenes, the structure in the first example looks more like public class Attack { public Attack()...


0

Just add this script on the object you want to get destroyed as soon as it leaves view: using UnityEngine; public class DestroyWhenInvisible: MonoBehaviour { void OnBecameInvisible() { Destroy(this.gameObject); } } However, in many cases this will go a bit too far. There might be situations where an object becomes invisible for another ...


1

There are plenty of tutorials about infinite procedural generation. Usually they all have the behaviour of cleaning up objects that are left behind the player, and creating objects in front of the player when required. It can be done in multiple ways. If you just want to know if the object is off screen or not, this question may help: Identify whether ...


0

The problem that you have is that you are referencing an Image component in your scripts. Image is a component of UnityEngine.UI which main purpose is to draw Sprite in Canvas. When you are doing this.profilePic = profilePic you are saying that your variable should reference an Image component that you have passed to a method. But still you have a logical ...


0

How I normally handle this type of thing is by having my player script store and operate on properties like Health, and then have a separate script attached to a Canvas object that simply reads those properties from the player script and displays them on the UI. Normally, the player script would look something like this... // Attach this script to the ...


0

I believe the problem you are experiencing is that while wind can blow in any direction from 0 to 360 degrees, your particles can only move aligned to the grid you've established. To remedy this, I would give each particle a real position, but snap each particle to your grid. That way, diagonal movements are still accounted for, but they don't cause ...


1

I'm sorry, but the script in the question tries to do so many things at once in such a convoluted way that I gave up trying to understand how it works. So I decided to just rewrite it from scratch. This script simply manages the value Charge between 0.0f and 1.0f. When the player presses space, the charge gets depleted and the property IsFiring is true, ...


0

Your main problem here is that you're trying to put code into a field initializer that is not valid there. As your error messages are telling you, field initializers are not allowed to reference non-static members, because when they run, by definition, the instance they're running for hasn't finished initializing yet! You have two main options (which are ...


Top 50 recent answers are included