Tag Info

Hot answers tagged

7

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

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 ...


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 ...


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!"); ...


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 ...


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 ...


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 ...



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