Tag Info

Hot answers tagged

9

let Arr be an array of Colour let N be the number of colors in the array let t be the 0..1 float value float scaledT = t* (float)(N-1); Color prevC = Arr[(int)scaledT]; Color nextC = Arr[(int)(scaledT+1f)]; float newt = scaledT - (float)((int)scaledT); finaly you can use Lerp Color.Lerp(prevC, nextC, newT)


8

I assume you have ´character´ class or something similar. Why not just do it like this: Character selectedCharacter = currentSelection; And when showing or otherwise manipulating other characters you could just do: if( charactersList[i] == selectedCharacter ) { // It's the selected character } else { // it's not the selected character }


6

Full issue message: error CS0121: The call is ambiguous between the following methods or properties: UnityEngine.Vector2.operator +(UnityEngine.Vector2, UnityEngine.Vector2)' andUnityEngine.Vector3.operator +(UnityEngine.Vector3, UnityEngine.Vector3)' Unity provided a way to implicitly convert a Vector3 to a Vector2 and vice-versa. This causes an ...


4

When modifying a prefab in the scene, you can save the changes to be reflected on all instances of the prefab by clicking the Apply button in the Inspector tab - children, component values, everything on and under the prefab will get saved and applied to all. So, add your child objects to one instance of the prefab in the scene, select the top-level of the ...


3

If you've already saved your GameObjects as a prefab, you can add the GameObjects to one instance of your prefab. When you click on the instance of the prefab, an 'apply' option should show up in the inspector. If you click that it will overwrite the prefab with the properties on that particular instance and then apply that to all the instances of that ...


3

Original RenderTexture image on the left, edited Texture2D image on the right. public class PixelChange : MonoBehaviour { public RenderTexture renderTexture; // renderTextuer that you will be rendering stuff on public Renderer renderer; // renderer in which you will apply changed texture Texture2D texture; void Start () { texture = new Texture2D ...


3

As others have pointed, your animation is most likely overwriting the transform of your GameObject. Generally, you can't (cleanly) have both an animation and a script modify the transform of the same GameObject without conflicting between each other. So how about, instead of fighting against Unity to get an animation and a script to modify the same ...


3

Because the default settings on the web player are low and on the unity editor are good. You can go to Edit > Project Settings > Quality, the default settings checkbox is in green light, you can change it in row Default and pressing the dropdown arrow.


2

The WaitForSeconds() command does not run/return when Time.timeScale is equal to 0 because it relies on Time.timeScale. I'm assuming because you mention pausing, you set the Time.TimeScale to 0, then call "yield return new WaitForSeconds(15f)" and unpause with Time.timeScale = 1. You can use Unity's Time.unscaledDeltaTime, which is how much real time has ...


2

It's not wrong with the camera or with the content of any script you might have. This error occurs when you have a script attached to a gameobject and you deleted, moved or renamed it outside of unity. Unity can't find the related script for the MonoBehaviour component. If you want to rename or move a script do it always in Unity. To solve your error, just ...


2

Let me rename the vars (for clarity): Vector3 pos3d = new Vector3 (1f, 2f, 3f); Vector2 pos2d = new Vector2 (1f, 2f); Answer It is because of the section pos3d + pos2d of the line. This part is really ambiguous while the += is not. Let me clarify why one and why the other. Analysis 1 In this line transform.position = pos3d + pos2d; the compiler ...


2

I solved this problem by using buttons instead of toggles. First define two button styles before any functions: private static GUIStyle ToggleButtonStyleNormal = null; private static GUIStyle ToggleButtonStyleToggled = null; Then in OnInspectorGui() make sure they are generated if null: if ( ToggleButtonStyleNormal == null ) { ToggleButtonStyleNormal ...


2

Toggle returns the current state of the button - either the same state passed in value or the new value as changed by the user. So a better pattern would be... // TODO: Initialize these with GUIContent private GUIContent _toggleButtonDepressedLabel; private GUIContent _toggleButtonDefaultLabel; // Current toggle state bool _toggleButtonState; void ...


1

Although it may not be what you are looking for, I generated this to show how to use the stencil buffer to achieve what you want: The "black-shader" could just return (0,0,0,1); but could also sample from a texture (animated gradient, etc.)


1

I suggest you to look at camera's clipping planes. Play with near and far and see what changes. Near plane tells camera where to start rendering the scene and far plane tells where to stop rendering. Maybe your near plane is too far and parts of your level which are closer to your camera are not rendered. You could get more info from the camera docs


1

Scripting languages often expose a set of API functions that allow you to inspect and determine attributes about a loaded script, in your case what functions are defined. This varies by scripting language naturally and will also depend on your native language to scripting language bindings. In Lua for example, I can load a script and then check whether a ...


1

The rigidbody2D's transform has up, right, and forward properties that'll tell you what's up, right, or forward for the object, respectively. In 2D, only two of those will actually be useful to you, and I imagine those would be up and right. So, if you want to apply the force in the object's up direction, do away with Vector3 heading = ...; and calculate ...


1

I guess you refers to this shader. That's not an "anomaly", it's how this shader is supposed to work(not a great result imho). So let's have a quick look to the relevant code: float3 norm = mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal); This first line transforms the normal from object space to view space. float2 offset = ...


1

I figured out how to make certain objects like my Camera and Canvas persist across scenes, but I can't figure out how to access them in the editor from scenes in which they're not instantiated. A scene is basically a collection of objects (and serialized properties) that the engine bundles and can load together. As such, it's allowed to cross ...


1

if(Input.GetMouseButtonUp(0)) this.gameObject.SetActive(false); This will hide the "button" completely from your scene until you decide otherwise. I recommend you go through the docs so you can figure out these answers by yourself.


1

I played the game. Each of the separate games appear to be "maps" loaded in the same basic surgery game. Each "map" seems to have a pre-determined script that the player follows, or else. Each button/tool is given a ToolID. For the heart-surgery "map": toolsNeeded = {1,3,2,6,3,5,1,0}; //Loaded from "map" currentToolIndex = 0; //New game while(patientAlive ...


1

The camera up-vector A property of the camera you could use to solve this problem is the up-vector. This vector indicates which direction in 3D space should correspond with the (upward) vertical axis of your screen. Usually, cameras will use the positive y-axis for this, thus: (0, 1, 0). The scalar product of two vectors The scalar product of two 3D ...


1

There is few ways to do this. Store information of last gifting time to: Local device ( pc, phone, table or what ever is the gaming device) Cloud service. However, this is harder method and requires the actual service hosted at somewhere in internet. File writing method is quite simple to do. Store time to variable When game exits, write time to ...


1

One approach that can be taken with multiple color transitions is to leverage a Gradient. By exposing a public variable of this type a developer an use the Inspector to launch the Gradient Editor to design a gradient containing any number of colors. This editor allows you to use a the unity color pickers, fine tune placement of the color/alpha keys and ...


1

public float every; //The public variable "every" refers to "Lerp the color every X" float colorstep; Color[] colors = new Color[4]; //Insert how many colors you want to lerp between here, hard coded to 4 int i; Color lerpedColor = Color.red; //This should optimally be the color you are going to begin with void Start () { //In here, set the array ...


1

Oh yeah, the unity remote app can be a pain in the ass. It seems like you set up everything correctly. To see if everything works fine just try to build and run the app for your phone... if it can be built and pushed to your phone everything should be alright. If you can push the app through unity on your phone I hopefully have a solution for you, which ...


1

Your problem is transform.up = TowardOrigin;. I didn't know you could actually set transform.up until now, since it's actually a summary of a more complex state of the object -- its rotation. Setting it tells Unity to orient your object along that axis, but doesn't tell Unity to keep transform.forward as close as possible to what it used to be. You're ...


1

Simply set the object's Transform.position to Vector3.Lerp(Vector3 A, Vector3 B, percent completion


1

The clean way is to add a new property, eg called animatedScale, to your script which you animate instead of directly animating the object's scale. then, in your Update, you set the gameobjects scale to 'animatedScale * yourScale' or whatever you want. This way the animation and your scaling are seperated and applied in a controlled way.


1

I think you have to move all procedural animation to LateUpdate(). This will allow you to override Unity animation. UPD: and you have to animate lossyScale instead on localScale, since localScale is animated by Unity (look for Mitchell's answer for details)



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