Hot answers tagged

6

The issue in your code is that you only check for the key press in the OnTriggerEnter function, which only gets called when the collider enters the trigger. What you probably want to do instead is check for the keypress inside the OnTriggerStay function, which gets called while the collider lies inside the trigger.


4

I have little experience using Unity directly, but I've been a level designer for years and a much easier approach rather than worrying about cutting holes into your terrain is to simply build up a C shaped ridge in your terrain for the size of your cave and then cover it with rock meshes to give it the illusion of a cave. Another approach is that you ...


3

Is the script attached to the game object of one of the two chests CurrentChest and OpenChest? Then keep in mind that deactivating a game object also deactivates all scripts attached to it. That means any events on them won't fire anymore. You likely only want to disable specific components of the chests.


3

Separated grid Randomly pick a box that hasn't been chosen yet, then randomly place the item within that grid space. The space between the boxes is enough so that items placed on the edge of a box doesn't intersect with an item placed on the edge of an adjacent box. This can be implemented pretty simply with a list and a bit of math. Try, and try again ...


2

The solution by Qbix works when the list of possible functions is static. But what if the list is only known at runtime? First you need to wrap the function calls into delegates, so you can treat them as variables. A premade delegate from the .NET framework which takes no arguments and returns no arguments is Action (There are also template delegates for ...


2

Well, everything is simple and complicated, and simple again at the same time. Despite the visual changes in the inspector - it doesn't mean that the data were actually changed. It looks like everything works fine, but......In my opinion it is shortcoming of the Unity For correctly work you should use few things: GUI.changed - returns true if any ...


2

It doesn't count unique vertices (as defined by their positions), but vertices as they are used to generate triangles. Look at your list, vertex #0 and #13 are the same vertex, but as DM Gregory's answer will detail, have other different attributes like surface normals, so even indexed, the positions aren't enough to index (although in theory you could ...


2

There may be two reasons why it's not working. You have not attached the script to any object which is in the hierarchy window. You have not assigned a prefab in the stone_3 variable field.


1

You can disable a component (or even destroy it - it'll be removed from your gameObject) to tell Unity to stop calling its Update method. To disable a component, from inside your tilt component, you can do this in the Update method: if ( PlayerControll.instance.isAlive == false ) { this.enabled = false; } To destroy your tilt component (remove it ...


1

In computer graphics, a vertex is usually more than just a position: it also includes texture coordinates and normal (facing direction) information (among other situational data, like vertex colours, blend weights, tangent vectors, etc...) The vertex processing part of the graphics pipeline doesn't index these sets of information independently — all the ...


1

Unity's InputManager isn't well suited for this task, I strongly recommend interfacing directly with the APIs that SteamVR provides for Unity games: SteamVR_Controller.Device.GetAxis is most likely going to be the easiest way to get the behavior you want: public Vector2 GetAxis(EVRButtonId buttonId = EVRButtonId.k_EButton_SteamVR_Touchpad) So to treat it ...


1

This is called arrival. It's a steering behavior. The basic concept is: Apply an acceleration towards the target position (alternatively, you can simply set the velocity if you're not using acceleration) When within a defined range of the target object, start applying acceleration away from the object, this acceleration is scaled based on the distance to ...


1

Most games separate the visual framerate from the physical framerate. The gameplay itself is always calcualted with a fixed number of frames per second, but the drawing only happens when there is time left. That means the game might run at 60 fps internally but only show you 20 of those frames on the screen. This works quite well because in most games the ...


1

The solution to this is to use a Coroutine that waits for the variable to be destroyed. This guarantees that it will be able to make the MeshCollider. Here is a piece of sample code that could be used to implement a similar solution. Vector3[] v3 IEnumerator Start(){ PolygonCollider2D polyCollider = this.gameObject.GetComponent<PolygonCollider2D>()...


1

I'm not sure filling sharedMesh.vertices will be enough to convert your PolygonCollider2D into a MeshCollider. From my (not long enough and too basic) tests, when you try to create a MeshCollider and only give it vertices it doesn't work. Your MeshCollider will need vertices but also triangles. After getting the polygon points you might have to compute all ...


1

It's reading one character at a time, so it's not properly escaping the new line. I would suggest looking for escape characters in your Stampa() function, and if it's an escape character, read the next character in at the same time. Something like: void Stampa(string stringa, int i) { string r = stringa[i]; if (r == '\\') r += stringa[i+1]; ...


1

You can try Application.LoadLevelAdditive Unlike LoadLevel, LoadLevelAdditive does not destroy objects in the current level. Objects from the new level are added to the current scene. This is useful for creating continuous virtual worlds, where more content is loaded in as you walk through the environment.


1

Simplest way in the world: Random random = new Random(); // it will roll from 0 (inclusive) to 2 (exclusive) so 0 and 1 int number = number.Next(0, 2); if(number == 0) func1(); else if(number == 1) func2();


1

I found the solution; it turned out to be a beginner's mistake. I locked the Y-axis in the Rigidbody2D component (to prevent the gravity effect pulling my character downwards all the time). I unchecked that and set the Gravity Scale to 0 and it is working!



Only top voted, non community-wiki answers of a minimum length are eligible