New answers tagged

2

I recommend always asking about your goal, rather than the method you think might help you achieve your goal. ie. "How can I draw a rectangle over 3D content that's in front of it in HDRP?" rather than "How do I draw a world rectangle as GUI?" This avoids the X/Y problem, helping you get the outcome you want without distractions or unnecessary constraints. ...


3

The tutorial, "Ruby's Adventure: 2D Beginner" is a 3D project. I restarted the tutorial and changed it to 2D using the menu "Edit -> Project Settings... -> Editor -> Default Behavior Mode". Next, I followed Cedric Degottex's suggestion in the comments for the tutorial by opening "Window > Package Manager", and installing the "2D Sprite" and "2D Tilemap ...


0

Some developers hate singletons, but the canonical answer is to make a single long-lived class instance into a singleton, so there is one instance which can be accessed from any other script. public class GameManager : MonoBehaviour { public static GameManager Instance { get; private set; } void Awake() { Instance = this; } } Then ...


2

Answer I figured it out: there's absolutely nothing wrong with changing the direction of your rigidbody's velocity. The problem was using transform.up to rotate the game object itself. I replaced that with rb.MoveRotation(rb.rotation + angle) and it's buttery smooth now. Takeaway In general, if there's anything I've learned from this project, it's that ...


0

Depending on where you are playing the video from, either local or from a url. You have to set the video player to the clip. The paths change depending on what platform you build to so if you want android then you would get the file from streaming assets path #if !UNITY_EDITOR && UNITY_ANDROID url = Application.streamingAssetsPath + "/" +...


1

I made a custom toolbar. I uploaded it in my github


0

in unity basically pooling means: instead of using Instatntiate() that makes new object in the scene that takes cpu performance to allocate, make all of needed object on the start of the scene and only enable and disable them and only make new object when all of you instantiated objects are active and are not ready to reuse. you can use a foreach or for ...


0

You could have a timer as class' member instead of a local variable in your coroutine. private float powerupTimer; private IEnumerator powerupCoroutine; private void OnTriggerEnter(Collider other) { if (other.CompareTag("Powerup")) { hasPowerup = true; Destroy(other.gameObject); powerupTimer += 5; if(powerupCoroutine ...


0

As per the comments it doesn't look possible to mix input systems together. I will use the answer given by IQew and use plain Image UI Element to interact with the mouse, drag the object and then, when it is in game I will switch it to sprite , either by destroying the gameObject with the image attached and creating a new Sprite in place, or just toggling ...


1

In the updatescore method you simply ask, whether isGameActive is true or not.


2

You're trying to limit double-counting using your results list: if (result.Contains(neighbor)) { continue; } result.Add(neighbor); The trouble is, you're using a different result list in each iteration: We call FindAllRecursiveNeighbours with bubble A's position. We make a new result list for A, and find all A's neighbours, including bubble B. Bubble ...


0

welcome the community. that is so simple. you need to define some flag for running of your game and instead of writing logic of start game in Start(){} function that is called on start of game object, you should call it for example on button press and make your update function that is called every frame only Work if a bool flag is True. i re-write your code ...


1

The thing is that you look for neighbours and then you call the same method again on the neighbours, which means that you can find the origin again, as well. This causes an infinite loop meaning StackOverFlow in this case. It might make more sense to find a clever way to give each Bubble an Array or List of Bubbles (Neighbours) and set them during the level ...


0

In order to get the particles behind UI elements you have to change the "Order in Layer" for either the canvas for the UI elements, the VFX Layer or both depending on what's best for your project right now. Create a new project and try this: Set the camera to orthographic and give it a reasonable size for your target resolution Create an Image in the scene ...


0

first, welcome to this community. second, before making any real project try to read all of its documents and do some tests with it. on canvas select scale with screen size and drag anchors to fill the place you want. so your object scales to fill in different phone screen sizes and ratios. about particles and obstacles, it depends what tools are you ...


1

If you need the Image enabled during the process but also do not want it to 'receive input' you can get a reference to the image and disable the Raycast Target. Then re-enable it when you need it. If you never want it to be selectable you can just uncheck the box in the bottom right. image.raycastTarget = false;


0

TLDR: Add the SerializeField attribute to the GameManager variable in the PlayerController, then reference the desired GameManager instance through the inspector. In the PlayerController class you have included a variable of the type GameManager, but you have not populated the variable with any instance of GameManager. Populating variables and referencing ...


1

In a case like this you would either want to make that a public GameManager gameManager or add a [SerializeField]above the variable and simply drag it to the slot to set it. If you would like to keep it private you could either use a Gameobject.Find(); or something like FindObjectOfType() to set that manager in Start() After assigning your manager when ...


0

Use Wwise External Source plugin, described relatively well here. The docs on this feature are not the best, but the general workflow I used went something like this: Stored voice over files outside the Wwise project and Unity streaming assets folder (could be anywhere, I used a folder next to the Assets folder) Create a new Voice audio object in Wwise and ...


0

Input.gyro.attitude gives you a quaternion representing (a best estimate of) the device's absolute orientation in space - including its orientation relative to the north pole. But that's not what you want here. You want a measure of how the device is tilted relative to the gravity vector - no matter how we're oriented to north/south/east/west. // Get the ...


0

Near Clip Plane It sounds like you've misunderstood what a camera's near clip plane is. The official unity scripting manual describes the clip planes as: Clipping Planes: Distances from the camera to start and stop rendering. Near Plane: The closest point relative to the camera that drawing will occur. These planes create the camera's view frustum. The ...


0

Here are the things I have had to do to solve this issue before: Make sure you have Visual Studio Code set as your editor in the unity preferences. Make sure you have the C# Visual Studio Code extension installed. Check the VSCode OmniSharp logs for any errors. Let me know if this helps.


1

Do your entities both use box colliders? When two axis-aligned box colliders collide, then there isn't really a single collision point but rather a collision line on which the colliders touch. Unity is supposed to return multiple collision points in such a situation. That's why Collision2d.contacts is an array and not a single value. But your code only ...


0

Yes indeed it is possible with Layers. First create two layer in animator. Then increase layer "Wight" to 1. Now set animators like this. Not Add Two triggers to parameters for may be "Poison" and "Burn": And assign those parameters to Transitions buy click on transition arrow And also do Transition setting to your need. Now At last step set triggers ...


0

I managed to solve it by going through all the next steps. Did some research and found a thread where people write about going through similar or the same problem but didn't really gave me an answer. Restarted Unity and ensured all packages are updated, but the problem remained. Downgraded the project to 2019.2.7f2 and to 2019.2.1f1 (in Unity Hub), but ...


2

First of all I recommend not checking the doorLockState and globalDoorLock state in the update method. That method gets called on every frame (which impacts performance) and is better reserved for functions that actually needs to be checked constantly. (Like player movement) Now back on topic you want to be able to change the lock state of every door ...


2

As the documentation says, The Unity scripting API does not expose direct WebSocket access itself. But you can access the native web browser API by calling JavaScript from Unity C# scripts. Create a JavaScript file which defines the functions you need and implements them by calling native browser functionality. Give it the file extension .jslib Put it into ...


0

If you don't mind just create children to the object that would be hit. Let the children's names be indexes for your hit registry. In my example, I named the head hitbox as "0", chest as "1", arms as "2" and legs as "3". Attach a script for "Hit Registry" to them. Then you should have a public function in the parent object (the object that would be hit) to ...


0

To solve this I deleted com.google.android.gms.play-services-base-17.0.0 and androidx.annotation.annotation-1.0.0 from Plugins/Android folder.


0

I haven't found any information related to this. So the best solutions I can think of are only workarounds and there probably isn't any built in solutions to do this. It is very inconvenient indeed. [SerializeField] private GameObject _hammerHeadGameObject; [SerializeField] private LayerMask _impulseLayerMask; [SerializeField] private ...


0

you can make other colliding GameObject to define its own Event Function. for example other Object hast Enemy Class Component that has Die() function. so you have to write: Action myAction; void OnTriggerEnter(Collider other) { myAction= Other.GetComponent<Enemy>().Die; myAction.Invoke(); } if you want to check function of different classes you ...


1

Option A: For a project that we worked on, we had utilized grouping. It was one creature (with a model of many creatures), but had many hitboxes. When a hitbox HP became 0, it would divide the creature and create a second or third model. Option B: Utilize low-poly models. We had to use this a long time ago for massive battles with multiple mobs. Option C: ...


1

I had a similar problem, so I turned off Apply Root Motion in my character's Animator component.


1

I'm unable to reproduce the problem described in this question when using types that are derived from MonoBehaviour or ScriptableObject as shown above. Using the following code: public abstract class SomeBaseClass : ScriptableObject { public int baseClassInt = 5; } [CreateAssetMenu(fileName ="Derived.asset", menuName ="Testing/Some Derived Class")] ...


0

The Light component is used by the surrounding objects' shaders to compute how much illumination their surfaces should reflect. But from the perspective of the lightbulb itself, that light isn't shining onto the surface at all - the surface is facing directly away from the light. So it correctly does not reflect any of it. Some shaders will try to simulate ...


0

Just found a recent good article on Getting Real-World Objects into Unity 3D that adds a different and good prespective using MeshRoom and MeshMixer. The following image shows the three steps required to achieve it Take several photos, as many as possible, around the object and use MeshRoom to digitize it. This tutorial illustrates the process. Upon ...


0

It appears like you are looking at the inspector of one of several subsprites of an image asset you imported with the "Sprite Mode: Multiple" setting and then sliced with the sprite editor. The second screenshot, however, appears to have marked several actual tile images, not the subsprites created from them. It appears like they are using a separate image ...


1

For Unity version 2019 and up Go to Window Find package manager. Look for 2D Tilemap Editor. (Wait for a few seconds to load all the packages) Install it and you're good to go.


0

https://docs.unity3d.com/ScriptReference/MeshCollider.html as your mesh-collider is generated automatically, based on above reference, you can get the list of vertices and also bounds of collider you have. just check the Bigget X,Y and Lowest X,Y to set bounds of your 2d box-collider.


1

There's a cool way to render crisp lines and contours using small resolution textures! I usually see it being called Signed Distance Field Text Rendering - it's what TextMeshPro uses - but there's nothing stopping the technique from being used for other purposes. The general idea is that you pre-process the texture in a special way so that each pixel ...


0

See here and here. The gist is that on Android devices specifically, the values returned from Screen.dpi are often off because Android doesn't have the same info available (or in the presumed format) for Unity to crunch. So Unity forces the function Screen.dpi to call densityDpi instead. This method returns constant DPI densities provided by the ...


0

It is an old question - There doesn't still seem to be easy way to show clearly the origin and the bounds of a Tilemap, but it can be solved with a script that runs in the Editor like Philipp said. I created this script. Red border shows the Tilemap current bounds, green cross shows the 0,0,0 position of Tilemap. Script does take into account position of ...


0

using UnityEditor; using UnityEngine; [ExecuteInEditMode] public class GetTilemapCoordinate : MonoBehaviour { public Grid grid; public GetTilemapCoordinate() { SceneView.duringSceneGui += GetMousePosition; } public void GetMousePosition(SceneView scene) { Event e = Event.current; if (e != null) { ...


0

I share some code which will help you out: public float force = 5; public ForceMode forceMode = ForceMode.Impulse; private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("Enemy")) { Debug.Log("Collision"); health -= 20; //Check for death if (health <= 0) { ...


0

There is capsule collider attached to the bullet in the tutorial, But Mike Geig did not explain any thing about physics and collider, But as much i know unity "MonoBehavior" physics is not working with DOTS Entities. So you have to install either "Havok Physics" or "Unity Physics". More about Physics you can watch tutorials: Leveraging DOTS-powered ...


4

Save it to the hard drive instead. Saving large quantities of data in a non-volatile fashion is literally why hard drives were invented. If a player isn't interacting with it anymore, you won't need to rapidly access it, so why keep it in the RAM? Just save it to the your server's hard drive in a text file or something.


2

Great work on your code so far, it's not far off the solution. One issue you are having is the bounce is applied twice. That is if it's positioned and timed right you'll bounce left and right. The other is physics is processing the bounce first which is off course from your fixed direction. Note: For correctness I must mention setting velocity isn't the ...


14

One way you could solve this problem is not actually storing state on disk, but just setting up your generation code to use a seed for the random number generator, so it generates the same thing for a given area every time the area is generated, deterministically. Then you just keep the 1000 or so most recently visited areas in memory. When areas are ...


0

When you use LoadImage it resizes the texture for you. It could just as easily be new Texture2D(2,2). Also note that you don’t need to explicitly call compress or apply if you create the texture with the dxt format to begin with: //Use DXT5 for images which may have an alpha channel, or DXT1 for images that do not have one: Texture2D texture = new ...


36

First of all, are you sure you really need that? Have you calculated the memory footprint? A small back-of-the-envelope calculation: A single mob and its state should fit into 100 byte of data. Let's give it a whole kByte, in case you are doing something extraordinary. When a cell has 1000 such entities, it requires a MByte. If your world is 100x100 cells, ...


Top 50 recent answers are included