New answers tagged

1

Turns out there's EditorSceneManager.LoadSceneInPlayMode which does exactly what I'm looking for! Awesome. I had asked on the Unity Forum and found the answer there


2

Unfortunately, the only ways to load scenes are the two options you already mentioned. However, just because it’s in the list of scenes, doesn’t mean it needs to end up in the built game. There are two options here. The first option is to manually uncheck the checkboxes in the build settings next to all of the scenes that you don’t want to include whenever ...


0

Just use a boolean to keep track of whether you've ever assigned a value of up. If not, inject a value of up at a random position in your collection. private void AssignRandomDirection() { // No need for this to be a list, since you never add/remove elements. var directions = new Vector2[] { Vector2.up, Vector2.down, ...


0

Here is the following code I added to the LineRenderer to scroll the tiles texture. public class LineArrow : MonoBehaviour { public float scrollSpeed = 1f; public Renderer _renderer; // Start is called before the first frame update void Start() { _renderer = GetComponent<LineRenderer>(); } // Update is called once ...


0

Being modern phone is not important. first you need to check that your phone has Gyro asits most important feature that markerless AR use. next you have to check android device supports ARCORE and for Iphone Device You need to check if it Supports ARKIT. you can find list here: https://developers.google.com/ar/discover/supported-devices you need to ...


0

You can do it by accessing the angularVelocity directly as i commented earlier, however if you want to use the addTorque() you could use something like rigidbody.AddTorque(Vector3.up * speed, ForceMode.Acceleration); // or rigidbody.AddTorque(Vector3.up * speed, ForceMode.VelocityChange); Notice the second parameter, Acceleration and VelocityChange both ...


3

Just rounding the coordinates alone won't work. You need to figure out which block the ray collided with (the coordinates), and then which face of the block, the ray intersected. From there, you can get the surface normal of that block face. Using that normal vector, you can then compute the next integer coordinate of where the block should be placed. ...


0

Its quit simple, Here the code which will do the job: public void ScaleINOutAnimation(Transform objectTransform, float scaleIn, float scaleOut, float duration) { objectTransform.DOScale(scaleIn, duration).OnComplete(() => { Debug.Log("Scale In done."); objectTransform.DOScale(scaleOut, duration).OnComplete((...


2

I'd like to provide an updated version of @colourmath's solution for single pass stereo since unity has changed since then and you can use unity_StereoEyeIndex to your advantage. And since this thread is the easiest thing to find when searching for VR world position in post effect shader, I figured it would be good to help anyone searching for a solution. I ...


2

Simpler version, involve GC alloc on Animator.parameters, not cool for repeated call. public static bool HasParameter( string paramName, Animator animator ) { foreach( AnimatorControllerParameter param in animator.parameters ) { if( param.name == paramName ) return true; } return false; } // Usage sample public void ...


0

The problem with my code was with the way Unity's built-in function Collider2D.ClosestPoint(Vector2 position) works. The point returned by the function is not necessarily a point along the edge of the collider like I assumed it was - instead, if position is inside the collider, then it returns the same point. This creates a NaN when you divide by the ...


1

you can simply search for unity monobehavior callbacks. you can find the, in link below: https://docs.unity3d.com/ScriptReference/MonoBehaviour.html


2

The documentation of an API is generally a good place to go to if you want to find out the list of functions, types, et cetera in that API. Unity's documentation for MonoBehavior can be found here. It includes a complete list of methods and members for MonoBehavior, which can be clicked on to get more details. If the documentation alone is insufficient for ...


0

I figured out why they're running away. Because this model is so far away from the player, I made a duplicate player model and disabled the first one. After deleting the duplicate and using the original, it stopped the model from running away from the player.


3

It looks to me like the problem is just a typo here in your node type: public int fCost { get { return gCost = hCost; } } This should be a +, not an = This typo would result in your heuristic cost h alone being used when comparing items in the heap, so the algorithm would prefer nodes close to the target even if they have a larger ...


0

I think when you change render mode to screen space overlay then target display is not set to Display 1. So do the following I hope this will resolved the issue. Change Canvas render mode to "screen space to overlay". Change Target Display to "Display 1". Make sure one or more UI object in the Canvas is enabled. i.e a button or txt. "


0

The problem seems to be the inaccuracy observed on 'climbing down'. This can be fixed using a better sampling of raycast result while calculating the slope. One such method is to try a sphere cast with some extra raycast and using statistics (mean, median, mode). This method is very well illustrated in the following posts- 1.http://thehiddensignal.com/unity-...


0

While I'm pretty novice I thought I would chime in too! (ofc i'm open to feedback too!) IMO it seems you're pretty close. Rather than making multiple scripts to hold different enemies at this early phase, I agree with DMGregory's suggestion of using 1 prefab with different inputs. After Instantiating the prefab enemy object I like to make a reference to ...


0

I would 'move' the camera as you are doing now, but just use LookAt, or LookRotation, to point at the target. Lerping the transform.position should give you a smooth transition to the camera's rotation anyway, without the need to Slerp, but you could add some damping once you've got it working.


0

Because the system you are using is at least partially successful, I'd suggest there are two options here: The intermittent problem is due to the capsule collider on the Player Controller and (I assume) picking the first collision hit in the list. You could try grabbing all the hits into an array and loop over them to find the one with the lowest, or ...


0

Unfortunately, Unity's 3D collision structure doesn't contain all the information you need to compute angular effects from a collision unambiguously. We know the total linear impulse applied to the bodies but not the angular impulse. But we can do our best to approximate this by keeping track of our previous angular velocity, and applying the difference to ...


0

Assuming these two things: The asset exposes some API from which you can read the data you need Your "blocks" are saved as prefabs Then you should be able to write an editor script to bake out the data into a format you can read at runtime without having to load the blocks. Getting each block's path data It looks like you can use PrefabUtility....


0

physics engine that unity3d uses is non-deterministic. it means you cant predict exactly how it will move. so you best approach for you is to use rigidBody for one object and make rigidBody of another, kinematic. and just set rotation of first object to another using Transform and move second one as first one moves with some offset.


-1

I'd also recommend Unity Addressables. I created an article that'll help you upgrade from hard references to soft references with Addressables. https://thegamedev.guru/unity-addressables-learn-workflows/


1

It depends on the complexity of your character. Enumerations are fine for simpler characters, but it can become very problematic when character's abilities get expanded. Virtouso's answer is good, but I'd just like to add how I go about doing state machines a lot of the time. You can create a base class along these lines: public abstract class StateBase&...


0

Make one object a child of the other object or make both objects children of the same object. Add a rigidbody component to the parent object, but keep collider on both objects.


0

One thing you could do is, when one object experiences an impulse due to collision, apply it to the other too: public Rigidbody[] entangledBodies; void OnCollisionEnter(Collision collision) { // Unity sends the same impulse value to both participants in a collision, // even though one gets impulsed in the opposite direction. So which are we? ...


0

An animation triggered on instance X should not affect instance Y, whether they're the same class or different classes doesn't matter.


1

You are trying to get scene information before loading the scene try this it worked for me. [Test] public void Test_loadScene() { SceneManager.LoadScene(0); Scene scen_1 = SceneManager.GetSceneByBuildIndex(0); SceneManager.LoadScene(1); Scene scen_2 = SceneManager.GetSceneByBuildIndex(...


1

Hey there I see you are a new contributor. First off let me say that you can paste code directly in your question and that is desired. Secondly Have you tried loading both scenes before performing the test with : SceneManager.LoadScene("scene_name", LoadSceneMode.Additive);


1

for working with state pattern, first thing that comes to mind is enum and state. most problem is switch is not OO and most of the time its better to not to use switch-case. and you dont have much freedom to extend. its implemented like below: you can fill cases with any logic you want and you only have to change state variable to change running state. ...


0

As @DMGregory said there is no scene creation in non-editor mode. So my solution will be something like this: Create a new scene in the editor and add the new scene to build and then when user press "R" Load newly created scene. using UnityEngine; using UnityEngine.SceneManagement; public class ExampleClass : MonoBehaviour { void Start() { ...


0

i dont know how your ball is controlled but i assumed it is controlled by rigidBody physics. its obvious that for something that is controlled by physics you have some noisy jittery moves. your code works like attaching or childing camera to ball without deriving rotation. so camera will have the same jittey moves. best solution is to lerp camera to wanted ...


1

Here's another way to think of it: First, we figure out which direction in the parent space points toward world "up": Vector3 parentSpaceUp = transform.parent.InverseTransformDirection(Vector3.up); Then we orient ourselves to point forward in the parent's local coordinate, while aligning our own up vector as close as possible to this vertical: transform....


0

I have no idea what you're trying to do, but this does precisely what you described. public class AxisLock : MonoBehaviour { void Update() { Vector3 target; target.x = transform.parent.eulerAngles.x; target.y = transform.parent.eulerAngles.y; target.z = 0; transform.rotation = Quaternion.Euler(target); } ...


1

I have done this for automated medical CAD procedures as well as game engines, and will attempt to provide adequate information in order for you to accomplish this task on your own, but I will not be able to provide the script for you as this is a non-trivial task that requires a good deal of computational geometry and problem-solving. What you're asking is ...


0

To rotate a 2d vector (x, y) by a angle A to form a new vector (x2, y2): x2 = x * cos(A) - y * sin(A); y2 = x * sin(A) + y * cos(A); (A mathematical discussion of why is here if you want it) Because you want to rotate in both directions, you can simply form vectors with the angles +0.0001 and -0.0001 to get the rays either side of your central ray. Almost ...


3

The X/Y Problem strikes again! I'm trying to figure out how I can best offset a direction..I want the direction to always be slightly offset to the right of the object from the mouse position? And I mean not just to the right of the object itself, but to the right from where the mouse is. This is complicated, messy, and error prone. How much offset is ...


0

You can rotate it around the Y axis a bit. E.g. 10 degrees: direction = Quaternion.Euler(0, 10, 0) * direction;


1

You can design each event room on a separate tilemap and then save that tilemap as a prefab. Those prefabs can then be referenced by ScriptableObject's or directly by the script which does your dungeon generation. If your architecture allows for more than one tilemap, then you could simply instantiate the event rooms. This would have the advantage that the ...


0

It looks like Unity was not able to download the file. To fix this, I set the dl=1 in the Dropbox URL, instead of dl=0. Here is the code that made it work for me: public class DMROnline : MonoBehaviour { public string Active; public string Disable; public TextAsset textFile; void Start() { StartCoroutine(GetText()); } ...


0

i think dropBox is all about downloading. you have no access to serverside logic so for reading a file you have to download it im not sure about dropBox but requesting from A server of cloud from an app is different from browsers as you dont have sessions and cookies for app requests. certainly you need some authentication headers. try to send a request. if ...


0

If you want to rotate the video sphere counter to the head's rotation (to make it look like the head is rotating within a stationary sphere), then you want something like this on the sphere: // Track the sphere's starting orientation in your scene. Quaternion _startingOrientation; void Start() { _startingOrientation = transform.rotation; } // Re-...


2

You could implement most of the low level functionalities which are shared by many creatures as service-components which don't do much on their own but provide functionality to be used by the creature-specific behaviours. For example, if a lot of your entities should be able to follow a route of waypoints, create a WaypointFollow MonoBehaviour with methods ...


1

make your rigidBody Kinematic as navmesh and navmesh-Agent does not need physics to navigate your agent. make sure you object is grounded and be near of navigation mesh surface.


4

i think you are looking for a generic way to make an script that works for big range of NPC's. for making these types of behaviours, there are some techniques. you can research for each of them and think which one works for you. 1)FSM(finite state machine) -> HFSM(Hierarchical FSM), FSM with stack very easy to implement. simply a Switch-case programming or ...


0

The details vary widely, especially with the style of language (compiles versus interpreted, for example) and runtimes (native versus, say, browser-based). However the basic strokes are generally what you surmised. The editor executable for an engine generally knows how to recompile/repackage/et cetera the engine code to exclude the editor bits and alter ...


0

Nice UI, You are using the _arrowRawImage.rectTransform.position, that is getting the Vector of the raw image and not the arrow itself. Try working with the position of the arrow transform. Vector3 direction = (targetPosition - _arrowTransform.position); _arrowTransform.LookAt(direction);


0

I have a heavy solution, but it is working very good. For serialization use mem.cs. This is a scriptable object and a new one must be created from the asset menu in the projects area. It is used like a memory card, name it and insert it into any script to store specific data. **You must call mem?.Load() ** from any script you are using it in to load up the ...


0

As I mention in the linked answer, for full 6 DoF controls like spaceflight or swimming, it often works well to think of a corrective twist that you gradually apply to reassert your desired horizontal plane. Here's one way we can do this: First, we'll track a normal for the plane we want the ship to orient to when the player is not deliberately rolling. ...


Top 50 recent answers are included