Tag Info

Hot answers tagged

20

The Simple Way Add a quad which connects adjacent slices to each other. Texture this with a nice, melted cheese texture, complete with holes. As the slice is moved away the quad will naturally be stretched and thus stretch and skew the texture. This should look reasonable, although there will be no break. What to do here is make that texture an animated ...


7

What may be a good way of simulating entities which may vary a lot is to use a force field that you draw with a marching square algorithm. So the eating entity would be a set of fields that you have moving together using a flocking strategy or similar, to get a 'cell' effect. You have to use a number of force field large enough to allow for opening a ...


5

Fluid dynamics is one of those super hard things to set up, that once you've got it working allows for a whole range of interesting effects. It's probably overkill for most games, unless you actually need things to move like a fluid (as in, flow from one point to another). For soft-body masses, I would considering instead using nets of springs to simulate ...


5

As requested, one possible solution (with some flaws) is to use raycasting: Attaching a (C#) Script similar to this to the GameObject from which you want to check visibility would work: if(renderer.isVisible) //Check if Camera is turned towards the GameObject first { RaycastHit hit; // Calculate Ray direction Vector3 direction = ...


4

The three component vectors right, up, and forward probably point along the axes x, y, and z relative to the camera. So by adding these vectors together you can compose any other vector. It works the same as if you built a vector by specifying its three elements individually, except that you are adding three vectors which each have one non-zero element. ...


4

Absolutely, But not as simple as taking a return value of a normal function. First I assume your question isn't about sharing variables between two shader stages (vertex, fragment..etc) but actually between two shader (programs). Shaders are part of the rendering pipeline, every input/output should pass through the rendering pipeline and its memory is ...


3

PlayerPrefs provides a key-value store implemented in a platform appropriate manner.


3

It seems that you mix up GameObjects and Prefabs. When you say "Prefabs in another scenes" I think you are talking about Game Objects. Game Objects are objects, prefabs or not, who are in a scene. Prefabs are Game Objects that can be "saved" in your game folder. You can find more about Prefabs here. That said, and if I understand your question correctly, ...


3

Rigidbodies can be said to operate in two modes: Non-Kinematic has physics driven movement, the physics engine will consider any forces brought to bear on the object to calculate and apply changes to velocity, rotation and position. Kinematic lacks physics driven movement, the physics engine will not cause this object to move and any forces on the object ...


3

A few things catch my attention off the bat. First: filedata = sr.text.Split('\n').Select(s=>s.Split(',').ToList()).ToList(); Feels highly dubious to me. Are you sure this is doing what you expect it do be doing? Second: float halfWidth = mainCamera.aspect * (mainCamera.orthographicSize/100); float tempYOffset = ...


3

Various graph representations exist. Yours is an adjacency list with explicit vertices and implicit edges: Each vertex stores its adjacent vertices, each of which implies a directed edge to it. In the above, blue squares are vertex objects, arrows are references vertex A's list of vertices is [ B ] vertex B's list of vertices is [ A, C ] vertex C's list ...


3

You are not setting the Player transform of your clones, most likely. If I had to guess, you drag and drop the Player object onto your prefabs that are in your scene. This effectively maps your player onto your Transform object. However, if you clone the enemy, the object is a new instance, and the player transform is not initialized. Example on how to ...


3

This line: int num = TileNode z; You are declaring a TileNode with symbol z, but you are assigning that to an int. You can't assign a symbol declaration under any circumstances, so the compiler is yelling at you for it. It also doesn't make any sense; you probably want to assign that int to some property of z, right? This is doubly wrong because you ...


3

I don't think that you should go with static class members (you didn't mention language but I assume some kind of OOP) because that just hides "singleton" in a different place. Switch things around so your Game holds a bunch (map, set, list, array, whatever) of these across-room global puzzles. Make it so your rooms can ask the game about a puzzle it's ...


2

When you have deeply nested types, you should use a data format which supports unlimited nesting of objects. Two possible alternatives are the simple JSON and the more complex XML. Both formats look different but work surprisingly similar. They are basically key/value maps where values can also be either primitive data types, other key/value maps or lists of ...


2

Do it once for one component, then copy. Once completed for one component right click the component and choose "Copy component". Then you can right click the target component and select "Paste component values" and only change the array elements that differ between the two. Do it in code. Assign the sprites as defined in a text file programmatically. You ...


2

What you're looking for is the Time object. And Time.time in particular. Time.time contains the time in seconds since the game has started (or the level has been loaded). So you want to know how many seconds elapsed since the player is on the board. Just save the Time.time value when you want to start counting and then, in the Update method, you can easily ...


2

I recently faced the same problem. I was creating an scrollable image gallery in Unity, where images are downloaded in real-time from the a web server. On iOS devices I was reaching very fast the memory limit (with consequent app crash). That was caused due to a very big number of www objects leaved in the memory and never deleted or released. Also a very ...


2

Camera.WorldToViewportPoint() can be used to map from world to viewpoint coordinates. For static content the following line could be added to an Awake() method. transform.position = Camera.main.WorldToViewportPoint(transform.position); For dynamic content I add the GUIText or GUITexture to a child gameObject. Then on this child I attach a script with ...


2

If you want to change a Material in Unity you have to retrieve it first. If your GameObject uses a Material it means that it uses a Renderer. You can retrieve your object renderer using the internal variable renderer or get it using the GetComponent function. On the renderer object you will find a material property containing the active Material. For ...


2

Look at PlayerPrefs class. It's a key/value system that allows you to save, or read, a value.


2

Unity has three kinds of lights that work in real-time: Directional, point, and spot. Point lights just sit somewhere and emit light in all directions, which sounds a lot like the sun, but you would have to put the light so far away from everything and make it so strong that it may be unreasonable. Spot lights are the same, except they emit light in a cone ...


2

[EDIT] As your question, now clearer seems to be more about design and not so much a technical question I change my answer a bit. Your first attempt was the right one. Your sprite contains a drag&drop component. But it's necessary that it also contains the prefab it will instantiate once dropped in the game world. The main design is, from an inventory ...


2

No, but it will just be bad manners to write the same thing in every scripts and it can be a pain to debug if you have lots of function of collision detection in a lot of other scripts. You can use the method SendMessage() to communicate between scripts (or inside a script). You can read its documentation here e.g if(player.health == 0){ ...


2

Using a preset animation: So create preset animation in a 3D modelling software like Maya/Blender which has features like soft bodies and cloth that can do a good job simulating the pizza tearing. Export both the pizza texture AND the model animation to Unity (probably as a set of .obj models or some such). The model animation will represent the cheese ...


2

The easiest way I found to do this was as follows: Make sure to configure your canvas to use screen space based on the camera. Drag and drop your camera into the render camera property Detect if the rectangle contains the mouse coordinates using RectTransformUtility.RectangleContainsScreenPoint() method. Pass in your rectTransform object, the current ...


2

That's because every object has a script attached that's listening for a mouse down event. Each one checks to see if the mouse is down, and if it is, destroys itself. It's not clear how you want to select which object to destroy, but there are a few options: Use colliders on the objects you want to destroy, and inside the OnMouseDown method, put your ...


2

For the target frame rate to be applied in the editor it is important that the vsync is disabled. This can be changed using the Quality Settings GUI by selecting "Don't sync" or programmatically: QualitySettings.vSyncCount = 0


2

Chaining Input.KeyDown() and using a progress counter is a very rigid approach. You will find it difficult to modify or extend. You may find Input.inputString more adaptable. On each frame it will hold the ascii value of any keys pressed since the last frame. It could be used like this: public string cheatCode = "1234567890"; public float timeoutDuration ...


2

When facing this problem I found that I wanted the character to move forward at a velocity roughly proportional to how close they are to facing the target. When facing away from our target we "turn on the spot" (Red), when facing directly towards it we walk straight towards it (Green), when somewhere in between we will may walk slowly while turning (Blue ...



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