Tag Info

New answers tagged

0

I don't know of any plug and play solutions for it, but here is an algorithm that works in the pixel shader with just a texture as extra assets. The asset required is a small texture with a single row of some number of tiles, where the left most is the darkest and the right most the lightest. What happens then is (per frame): Take the buffer you want to ...


0

Your source texture is stored and converted regarding the individual platform settings. These settings include resolution, compress and the like. On Android for example you can choose between RGBA16 or ETC1 textures. Those are part of the build settings.


3

You should just have one component for your laser. The source object would just have the laser component. The "redirect" object will have an additional component called redirect. The laser component casts a ray, if that ray hits an object containing a redirect component, the "redirect" object powers up its own laser. Think of the laser more as a trigger to ...


0

GUI and 2D game objects are fundamentally different. Generally speaking, a GUI element is a 2D element (texture/text) that will accept some input and could potentially live in some screen hierarchy (e.g. a panel in a container). A 2D game object/element is... well, it's whatever a game object is in your game. It can move on its own, it could react to ...


2

In unity, SortingLayers (or camera layers for that matter) are not groups of object you should see them as tags : specifically for the sprites, sorting layers are used to define the order of render of the objects. you can go through all the sprite-renderers and check their layers and apply something to their transforms but that will consume "a lot"* of ...


0

Something like this: selected_character++; if (selected_character >= num_characters) { selected_character = 0; } and you can select the sprite by gameObject.GetComponent<SpriteRenderer>().sprite = Characters[selected_character]; You also have to declare a new class member to make the code above work: int selected_character = 0;


1

Depending on the amount of data you have to store PlayerPrefs should be perfect for that. If player prefs is not enough or does not suits your needs you can store project custom data in a text file (personally i place it in resources but it could be anywhere) and read it when needed for ex : i made a plugin for unity to define different sizes atlases path, ...


0

This is a major bug in Unity. For those who are stumbling here trying to find a solution, a very awesome gentlemen posted a fix over here at github https://github.com/hvs-clark/unity-android-rotation-lock Hopefully Unity fixes this crazy bug soon, so we don't have to use workarounds like this in the future. From what I read, it is by design, which in my ...


1

What I've found more useful in Unity is to really take advantage of editor, and realise the fact that you're working towards a solution that is drag and drop able rather than flexible in code. An enemy movement in Unity could be represented by a single method, but I believe it would be much better, and much more to the style of Unity to have separate ...


0

Instead of changing the render mode of the canvas you could instantiate the 3d model and a Camera that points at it in an unused part of the scene (or set the Camera culling settings to only render the 3d model). That camera then renders to a texture that is used by an Image element in the alternate GUI. You'll need Unity Pro though.


1

Use a bool. Just have a boolean value that gets flipped when the first button is pressed: using UnityEngine; using System.Collections;![alt text][3] public class window : MonoBehaviour { private bool render = false; private bool redWindow = true; public Rect windowRect0 = new Rect(20, 20, 120, 50); public Rect windowRect1 = new ...


0

Make sure that you have selected a Game view like below:


0

Ok seems as no one is replying to you, I will provide you with a basic commented example. I assume you have a "Resources" folder inside of your "Assets" folder. I also assume you have a "Prefabs" folder inside of your "Resources" folder. You will need to create an empty GameObject in your scene. Attach a SpriteRenderer component to that object and then ...


8

Applying the RequireComponent decoration to a script will ensure that the GameObject has the specified component. If the component is missing: Unity will attempt to add a component of this type for you, If this fails (e.g. mixing RigidBody/RigidBody2D) then the script will refuse to attach. C# sample: [RequireComponent (typeof (Rigidbody))] public ...


3

Unity has built in functionality for this called RequireComponent. Used like this in Unityscript: @script RequireComponent(Terrain) This will actually automatically add a Terrain component to the object if it doesn't have one already. If the user removes the Terrain component, your script will throw a compile error about the missing component.


1

Two methods come to mind, but none are very elegant. 1) Implement OnValidate(). The downside is that's it's called only when modifying component's values, or entering/exiting game mode. void OnValidate() { if (GetComponent<Terrain>() == null) { Debug.LogError("You can't attach this component without terrain!"); ...


0

This will check whether every tile in a column has the same texture. You should be able to modify it to suit your needs. You also need to set up the board in the inspector. Set the board size to 5, then each column size to 5, then drag over all 25 gameObjects. using UnityEngine; using System.Collections; using System.Collections.Generic; public class ...


0

public class ClickTest : MonoBehaviour { // public GameObject red, red2, yellow, yellow2, MainCamera; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if (Input.GetMouseButtonDown(0)) { Debug.Log("Pressed left click, casting ray."); CastRay(); ...


1

Here's how I've approached this situation in Unity in the past: I create a custom shield shader that accepts some number of vector parameters (typically 3 or 4), each representing a recent hit. The xyz components are the position of the hit in local coordinates, and the w component is the intensity. Within the fragment shader, I compute the object-space ...


0

The story like this.... Unity Input Manager pain is lasting for years. On Unity site you can find request on the forum for InputManager programmatic access dating from 2004, and feedback from 2009 with state planned today 2014. Below are some of the problems. 1) Ingame input controller mapping. Unity have user interface for mapping predefined bindings ...


1

Memory leaks in Unity can occur on several places. But to help you in the right direction, one of the most common leaks in unity would be the Texture/ material leaks Imperfect loops (for, foreach, while, etc) These leaks are often hard to track and can lead to crashes. To properly chase them down you first want to make sure that you have no warning ...


1

I'm fairly certain, though someone will no doubt prove me wrong, that you can not change individual elements in the mesh arrays of vertices, triangles, uvs etc. That is why when you work with procedural meshes you always update the entire array at once when you've finished modifying it. The reason for this is that mesh.uv gives you a copy of the mesh uvs ...


1

It looks like you have your score working using Time.time as the counter. I thought it may be helpful to explain what was happening when the code in your question is executed. When game starts and the Start() method runs it calls StartCoroutine (FeetScoreCounter()) When FeetScoreCounter() runs it immediately yields for one second, then after that delay it ...


0

This was the correct solution, where it converts score (float) to an integer.


0

This can be done with a short timer. It is probably not a problem if the animation doesn't start immediately when the character starts falling. public float delay = 0.1f; // Animation starts after 0.1 seconds of falling private float lastCollision = 0.0f; void Update() { if(Time.timeSinceLevelLoad > lastCollision + delay) { animator.Play ...


1

TextMesh[] child = GetComponentsInChildren<TextMesh> (); This line (and the three after it) is always getting the first three TextMeshes in the parent object's child hierarchy - not the hierarchy of the newatom you've just created. That means that each time you create a new atom, you're overwriting the labels on the first atom you created, leaving ...


2

I just tested this using the following code: void OnCollisionEnter( Collision collision ) { this.enabled = false; Debug.Log( "Collided with " + collision.gameObject.tag ); } void Update() { if( this.enabled ) { Debug.Log( "Enabled" ); return; } Debug.Log( "Disabled" ); } "Enabled" was displayed until the object ...


0

I think this document from the Unity help should be useful. Look to the diagram at the bottom of the page. Physics and collisions are processed before the game logic so if you disable an object during collision it will become disabled after its next update.


2

For states, I usually use Enums, and then do a switch statement within the Update method. Enabling/disabling components is probably easier than adding/removing them. If you need to listen for or be ready to execute a method that should only happen within a specific state, check the state at the start of the method. If the file gets too long and confusing, ...


1

The coroutine itself will pause, but the code that called StartCoroutine() will keep going. So in this case, WaitTime() will pause but OnTriggerEnter2D() will keep going. What you probably want instead is for the entire button logic to go in the coroutine. Then it won't matter that OnTriggerEnter2D() keeps going, since starting the coroutine is all it does. ...


1

Your WaitTime Coroutine will not pause the evaluation of the following code. The Coroutine will be kicked off and logic will immediately continue. Your Coroutine is waiting 3 seconds and will call that print function wherever it resides but that's all it will do. You should probably go with something like: private float triggerEnterTime = 0; void ...


3

You want your webserver access to go through HTTPS; that will encrypt the traffic so people in the middle can't read it.


0

I think it would be useful for you to try this program "bmglyph" http://www.bmglyph.com/ You can generate a character set with the font you like and export the font atlas in unity native format and in Cocos2D format (the format used by NGUI). Then you can look at how the program generate the .fnt and match it against what you already have and see if you are ...


0

Unity's Entity-Component-System implementation isn't an ideal model on which to base a custom ECS. Unity favors ease of use over strict adherence to the ECS paradigm and made lots of trade-offs to serve that end. Where Unity falls short of a pure ECS is the lack of separation between data and logic. In a pure ECS components contain only data and the logic ...


0

If you could generate a texture which is about the normal on the surface of the object you want to show the shield. There is no need for shaders. First, you need to prepare a cellular texture like the reaction in the picture, which should be transparent. Then, about the reaction when hit by the beam. Then, you need to prepare a(maybe several) dome for ...


3

It seems that something is going wrong when you create the textures for the individual characters. First, if we look closely, we see that it's not just the o, g and 3 characters are badly positioned: As Petr Abdulin points out: The base coordinate for your sprites is "left,bottom" (classic Cartesian) which is correct. Your renderer assumes ...


1

Movement should never be dependent on framerate. Bob Nystrom wrote an excellent summary of how to write a game loop that is independent of framerate. Check it out here. He starts with the most basic game loop then makes incremental improvements, discussing the motivation behind each iteration. I've added his code here but you should really check the article ...


1

You need to separate your games logic from display logic. Game logic should run at some fixed rate (e.g. 100 ms). Display should query the state of the game and display it at unconnected rate (e.g. 10-20 ms). That way your display performance never affects the game.


4

The reason you are getting this behaviour is because of coordinate system. The base coordinate for your sprites is "left,bottom" (classic Cartesian) however all offsets in fnt files are assuming inverted Y axis (drawing from "left,top" of the sprite). So instead of (you may notice this gives correct align, but on the top, i.e. g goes up instead of down): ...


3

I can't add a comment because my reputation isn't high enough, so this isn't really an answer. I thought the o's were offset differently as well, but when I used a ruler it turns out all three o's are on the same baseline. It is just an optical illusion from the dropped 'm'. In you code sample for extracting the glyphs from the font texture you use the ...


0

Yes, unless you click "Apply" in the editor any changes made to a prefab instance are considered as overriding the prefab and do not affect either the prefab or the other instances of the prefab. Once you instantiate the prefab you can change all aspects of that instance at your discretion. You do it the same exact way you manipulate any other object.


0

It depends on what type of collisions you want to resolve and who controls the wolf. Wolf is NPC If you want to resolve collisions with static environment you should think about using NavMeshAgent and bake static geometry to navigation mesh (so, that kind of collisions will never happened). If you want to collide wolf with other units with simple colliders ...


0

I had this same problem. I found out you have to call this from OnAnimatorIK, not an update function.


0

It was as easy as adding this to my IEnumerator Dead: if(hasPlayed == false){ audio.PlayOneShot(popAudio); hasPlayed = true; }


0

For a character object, mostly a capsule collider is enough. But ofcourse it depends on your game. Primitive colliders are more efficient compared to mesh colliders. You can use Profiler in Unity Pro versions and there's an internal profiler in Android and iOS for Indie versions. Although the pro Profiler obviously gives you detailed analysis, the internal ...


2

In my experience writing collision detection mesh-based collision (triangles versus other triangles) are the most expensive for of collision in physics engines (PhysX, Havok). Unity uses PhysX internally, so this is no different. Because each computer and platform perform differently, exact numbers cannot be provided, but generally speaking the relative ...


0

I found the problem. I had a wrong value on the vertex for an edge. My edge table said that for the edge 10 the vertex were 2 and 4 when they should be 2 and 6. Thank you for your time.


0

There are a few values that are crucial to multi-camera rendering in Unity: the culling mask, the clear flags, and the depth value. All three are mentioned in the camera component manual. mainCamera depth is -1, and NGUI Camera depth is 1. Unity draws cameras in ascending order. If you want the NGUI background behind the scene, you should flip those ...


0

To expand on crancran's answer, I will share our experiences with the ECS we use at work. Each component has the ability to be registered with a list of that component type. For example, our ModelComponent is registered with a ComponentList in it's create function, and removed in it's destroy function. Each frame, in the update loop, different systems are ...


0

Scripting is very different for various reasons from programming using C++ and very similar in the same time. Similarities: You'll often write function, classes and expressions You instruct the Engine what to do during the game / menu state. Differences: You need to compile C++ and you don't need to compile a script. C++ often offers lower level ...



Top 50 recent answers are included