Tag Info

New answers tagged

0

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

Let's unpack this, as it looks like you might be confusing Animator & Animation GetComponent<Animator>().animation.clip.length GetComponent<Animator>() returns an Animator component attached to the same game object as this script instance, if one exists. .animation tries to access a member called "animation" of that Animator object. ...


0

Wouldn't it be simpler to just use some integer state logic to drive the match comparisons? For example you could just keep track of each Tile's state and colour and do numerical comparisons instead of interrogating the actual texture of each gameObject? This has the added value of using a single Texture Atlas to store your tile textures and then just map ...


0

Maybe you spawn it too close/inside other colliders. Try spawning it at some distance.


0

When importing the animation there is a 'mirror animation' checkbox under the Animations Tab in the Inspector for that asset. If you check that box and rename the animation to "myanimation_mirror" or whatever then you should have 2 mirrored animations.


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

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


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


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


0

C++ and C# can interact quite easily. (In the practice C++ issues relative to name mangling often force to have an intermediate C layer) There are several resources you can have a look such as Mono P/Invoke docs and unity docs on native plugins. Calling a C# function from C++ code is simply as using a function pointer (a C# delegate can be marshalled to ...


0

Unity uses its own messaging system to call methods like Update. You can use it as well with for example Component.SendMessage. I think that the underlying implementation of the message system uses some form of reflection to determine what methods a class has and call the appropriate ones. (This post's answer explains it better)


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

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


0

You can use transform.localPosition to determine the position of the child object relative to its parent. The normalized version of this vector, .normalized, can be multiplied with the parent's scale to get the desired local position. You might want to set the scale of the parent to 1 and position the child accordingly if you don't already do so. ...


0

Turns out it was a bug in Unity.. All I had to do was restart the IDE.. Bad start from Unity.


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


0

So you have: Scene one that contains the camera and canvas (which have been marked don't destroy on load). It also has a script that does a load for scene two. Scene two that contains objects that need to reference the canvas in scene one. There's a few solutions for this: Solution one (low effort) Use GameObject.Find in Scene two to find the relevant ...


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


0

The state of the Shift key is checked in the ThirdPersonUserControl.cs script which isn't that difficult. To just swap the states you most likely (I haven't checked it!) would need to replace the #if !MOBILE_INPUT // walk speed multiplier if (Input.GetKey(KeyCode.LeftShift)) m_Move *= 0.5f; #endif with m_Move *= 0.5f; // Do it ...


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


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.


0

Somewhere in your code you're still setting the scale, so each time you try to modify the scale in the editor when running the game, it resets the scale. Without being able to look at your code it's impossible to tell you what is exactly causing the problem. In addition to that, when you are running an animation it overwrites the localScale, so you can't ...


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)


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.


0

If you have a circle sprite, that you want to rotate around a point other than its center, there is a much more effective way than this. Just go to the circle sprite in assets, and change the pivot of the sprite to the edge you want it to be. And that's it, you should get a rotation around that pivot, and when you scale, it'll stay the same. And don't ...


0

I try with some consideration. 1000 * 1000 is similar to a bitmap 1024*1024 , something you can easly store in memory. You can "cablate" the type and health of each block in the color / alpha of each pixel. Then you istantiate / deistantiate (or activate / deactivate) the blocks at runtime refering the camera position. So you can have 32 x 24 blocks (+ a ...


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


0

Below code will do what you want. You will need to save and load the value of "DateTime lastPlayDate" between sessions. using System; public class GameManager : MonoBehaviour { DateTime lastPlayDate; void Start() { lastPlayDate = DateTime.Now; } void Update() { DateTime currentTime = DateTime.Now; ...


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


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


0

If target is a transform, you want it to be target = pickedNumber.transform;, (no transform.position). If target is a Vector3, you want the next line to be ball.transform.position = Vector3.MoveTowards(transform.position, target, step);, (no target.position). I assume it's the first one, because of the wording of the error, but the second one is to show ...


0

My bitmap font has glyphs that are 22 pixels high. So it looks like the lineSpacing property needs 10x the pixel height of the glyphs to have no gap between lines, and no overlap. I don't know why, but empirically this appears to work. Seems related to this question: ...


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


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 }


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)


0

the fastest way is to make the camera child of the cube (in the editor), then in the Update() of the camera script use LookAt : void Update() { transform.LookAt(transform.parent); }


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


0

How about you write your own version, which leverages Color.Lerp()? A very simple version that takes 3 colors, and puts the second one right in the middle could look like this: Color Lerp3(Color a, Color b, Color c, float t) { if (t < 0.5f) // 0.0 to 0.5 goes to a -> b return Color.Lerp(a, b, t / 0.5f); else // 0.5 to 1.0 goes to b ...


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


0

I feel like there may be a better solution. The only reason I would see to lerp from color to color is if you were wanting to continuously change the hue... http://en.wikipedia.org/wiki/Hue Here's how to convert HSV to RGB: http://en.wikipedia.org/wiki/HSL_and_HSV#From_HSV With this you can use HSV colors, simply change the hue, then convert to RGB. ...


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


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

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


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


0

Z-buffering in a non-prerendered scene I will use the term pre-rendered background for what you describe as a 2.5D scene, as I assume this is what you are looking for. Ideally, you would want your character to be able to walk around the environment, as if it were not rendered as a flat image. Your character should be able to move behind and in front of ...


0

First off, there are a lot of games that did this back in the PS1 era (eg. FF8) so this is definitely a done thing. Basically, you need to render multiple times, and thus may want multiple cameras. First make the low-res collision geometry visible but the overlay and your characters are invisible, then render normally, then make the collision geometry ...


0

http://www.arongranberg.com/astar/docs/modifiers.php#simplesmooth If you're using Aron Granberg's pathfinder, then are you perhaps using one of the smoothing modifiers? This would result in the unit trying to optimize the path which would probably prevent the unit from hitting each node as it steps through the path. Or is the problem that you have a ...


0

Many moons ago when I first dabbled in pathfinding algorithms I used the following site to help me to first understand the basic fundamentals of how a simple pathfinder is meant to work, and what it's trying to achieve : http://www.policyalmanac.org/games/aStarTutorial.htm The A* algorithm is quite popular and suitable for most pathfinding needs in gaming. ...


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



Top 50 recent answers are included