Tag Info

New answers tagged

0

I'm using the following script which adds a targetAspect parameter to the camera and adapts its orthographicSize with respect to the screen ratio (more details in this blog post): using UnityEngine; using System.Collections; public class AspectRatioScript : MonoBehaviour { public float targetAspect; void Start () { float windowAspect ...


0

Basically you say that the Object follows your mouse coordinates after you clicked it. Use: if (Input.GetMouseButtonDown(0)){ /*Move Object which gets hit by the Raycast you shoot to Mouse coordinates */}; Also you have to convert the world coordinates to screen coordinates. Here is a good Tutorial for that: Klick


0

@Marcel's answer and code are great and helped me understand what was happening. It's the definitive answer. Just thought someone might also find useful what I ended up doing for my specific case: since I wanted something really really simple, one sprite to be always on screen, I came up with these few lines: public class CameraFit : MonoBehaviour { ...


0

A* is not designed to deal directly with realtime physics paths as there's a near infinite number of possible paths. walk 0.00001 units and jump walk 0.00002 units and jump walk 0.00003 units and jump ... You will first need to build a reduced list of path nodes to limit the possibilities. Every platforms start with 2 nodes with a path between, then add ...


0

The following should give you what you want, and is more simplified. public class GameTimer : MonoBehaviour { public float TimeRatio = 0.01f; // Game Day ratio to Real Day public float GameTime = 0; // Accumulated 'Game Time' in seconds public void Update() { ...


1

One way I'd go about is to set all textures in your materials to the smaller version for fast loading, and in the Resource folder (http://docs.unity3d.com/ScriptReference/Resources.html) you put the higher resolution versions with matching names ("Dirt" -> "Dirt_HD"). Then on devices that can handle it you have a script in your game that go through all the ...


1

You could try applying some form of vertex shader (or similar model modification) to fake some of the perspective: As I understand it, all models in the game are actually at a kind of shear slant. When viewed from above, it gives all the objects in the scene the same kind of look and perspective that they had in the snes days: There should be a way to ...


1

I think your problem might be related to the "Size" attribute of your camera. A higher value will cover a bigger area, and also make the displayed objects move slower. When using several cameras, this might cause the illusion of one objects being further/closer and moving slower/faster. This could also mess up the position where the object is being ...


2

Let's assume we have button A and button B and you want to be able to press both of them but not in the same frame. The general way of accomplishing this is the following: on button A key press if button B is currently pressed execute action end on button B key press if button A is currently pressed execute action end combining ...


0

I have a similar situation where I have numbers that animate on and off for a number puzzle game. I have a grid sprite sheet with each of these cells evenly spaced. I give each of these cells a number from 0 to X. From a cell number you can get a row and column like this: row = cellNumber / cellsWide; col = cellNumber % cellsWide; Then I have an XML ...


0

The relevant keyword to lookup is TextAsset When you drag a text file into Unity, it gets treated as a type 'TextAsset'. Actually load the data either by linking it through a serialized variable or by using Resources.Load (just like any other asset: image, prefab, whatever)


0

The simplest and probably fastest option would be to iterate your mesh and set edges vertices transparency to 0 (or any other desired value). This assumes you v got (fan shaped)adjacency information: foreach(Triangle t in mesh) { for(int i = 0; i < 3; i++) { if(t.Adj[i] == - 1) // or ==null, either way, on the edge { ...


1

Found! (Thank you Frame Debugger !) It turns out that Unity renders the Depth Texture in a separate pass before all geometry is rendered. It is hard to find how to include objects in this pass, and how to specify how they are drawn. The documentation is kind of vague, but it tells you that the "RenderType" is important without specifying what it should ...


1

The first parameter in Invoke takes only the name of the method you wish to call. Assuming PositionScript.instance is set to a MonoBehaviour component of some sort: PositionScript.instance.Invoke("MAttack",5f);


0

No, there is no performance issues with using static references. As it pertains to .net, you might even have better performance if you use static over instanced methods and fields (to such a little extent it is more a bit of trivia than something actually useful); I think the golden rule applies here: it is most important to make something that works and ...


-1

I decided to move everything up instead of the quad down.Not the optimal solution but perfect for my case


1

I am not quite sure what you are not understanding here, but I attempt to answer your question anyway. I am not quite getting what that does or what purpose it serves. In cases where you do not fill in the fields in the inspector (which requires them to be public), you need to find the instances of the needed components in code. The ...


1

Looks like the GUI is finishing building after the Close() by automatically calling EndVertical(). Try adding an GUILayout.EndVertical(); before the Close();. Or if that doesn't work delaying your Close call by one frame, something like: private bool close = false; public void OnGUI() { if(close){ Close(); return; } MapName = ...


1

The simplest, modestly realistic, model I can think of would be parameterized by the following: Mz The Turning Moment of the ship about the steering (ie Z or yaw) axis; L/2 The distance of the rudder from the turning axis, approximated as 1/2 the ship's length L; v The current linear velocity of the ship (relative to the water, not the land nearby, ...


1

An easy way if it is a simple animation (rotating gear, a piston, etc) would be to edit your animation to be exactly 1 second long then use the Animator.speed and set it to 1.0f / wanted_seconds, but that's not usable for complex character animations. You can figure out the length of the AnimationClip ( ...


0

Just drag the animator controller that has your animations in it to the Animator on your game object you should be able to access your animations again.


0

Check the barricade prefab to make sure the animation is set to the animation you are trying to invoke.


10

Keyboards have a key matrix, where the buttons have been arranged into something roughly square, with the keyswitches each being tied to one row and one column. The keyboard activates each row and then reads the columns. If you sketch this out you will see that some button combinations must activate "phantom" keys. You can fix this with one diode per button ...


17

Keyboards have hardware limitations on how many keys can be pressed and recognized at the same time. Your code is not the problem here, it's most likely the design of the keyboard.


1

The goal of sprite sheets is to reduce the number of texture bindings. As you probably need to bind different textures (other than your animations) during a single frame you'll always have at least one texture bind to select one of the spritesheets back on the next frame. Whichever texture your bind on the next frame will have the same penalty as the data ...


0

If the rudder turns left /, the boat turns left. If the rudder turns right \, the boat turns right. The more you turn the rudder, the greater the turn the boat takes. This assumes the rudder never turns 90+ degrees. The / and \ assume the boat is facing up ^. ^ | | | | --- / <---rudder


0

The way you are doing it is more or less the only way you can do it without sticking it into your build or into an asset bundle. There is a call for WWW that will auto-cache it for you, WWW.LoadFromCacheOrDownload, but it only works with asset bundles, so you could make a single texture asset bundle and cache it that way. If that's not an option, you'll have ...


6

I'd like to separete these things due to clearity reasons but I wonder if calling different FixedUpdate() functions would imply some kind of issue. For example: is their execution ensured to be called sequentially or they could run asincronously? Each callback of each MonoBehaviour will be called exactly once for each update loop, but you haven't ...


1

As said by Heisenbug is no built-in way to do this. My recommendation is to explore the UnityEvent namespace new to Unity 4.6 and above. This will allow you to expose functionality to designers that will allow them to rig up interesting inputs and receivers. You can go the extra mile and implement a custom editor with a serialized dictionary and button to ...


4

There's no built-in way to do that. If you prefer an event based solution you can wrap all input polling inside a component and expose the relative and subscribe for them. Some like: public EventHandler : MonoBehaviour { public event Action<Vector2> mouseCliked; void Update() { if (Input.GetMouseButtonDown(0)) { ...


0

The correct design choice here would be making one script and attaching it to the menu elements (I assume buttons) and define what each button will do on OnCollisionEnter() or OnMouseButtonDown(0). The main idea here is to differentiate clicks based on the name of the object that is being clicked on. void OnCollisionEnter(Collision col) { ...


0

Well, that is now the old-way to do GUI stuff. The new UI system that came with Unity 4.6 is, I think, extremely robust and easier to learn and work with. I strongly recommend you go through the new UI tutorials on Unity's new UI tutorials page and try to make your UI look like what it is seen on the tutorial you are working on by using the new UI system. ...


1

Go to Component / Rendering GUIText ;)


0

Do you really need the actual size in units? I mean, you can use the scale of your game objects to scale them up and down to create realisitics size relations between your objects. If you are creating your own 3d assets, you might want to handle the size of your models directly in your 3d model creation software and leave the scale to 1 in Unity (for ...


1

If a in-game day is 10 minutes in real life, you just need to get the number of seconds since the last 10 minutes and add a ratio to convert it to a 24 hours format. Get the number of seconds from the last 10 minutes. realTimeSecondsSinceTheLast10Minutes = (Minutes % 10) * 60 + seconds; Get the ratio between a 10 minutes day to a 24 hour day ratio = ...


0

For those who are interested the problem was that I tried to directly edit the UI.Text object, which was a child of an UI.InputField object. When I replaced public Text theText; with public InputField theText; , connected the actual InputField to that variable, not it's child the Text object, tried to change it with theText.text = "new text"; it worked ...


4

I see your problem, so let's run through the code here. At the start, you say there are (1440 * 60) seconds in a day, but then you proceed to define the number of hours in the day, the number of minutes in an hour, and the number of seconds in a minute. It works when the numbers are correct, but let's go through the logic of what happens if you define 600 ...


0

You can put your animations in an animator and add that animator to the character. The animator have parameter property so that you can control which animation to show. Further explanation are are given on their website.


2

_hourLength = _dayLength / HoursToTheDay; //determines how long an hour is _minuteLength = _hourLength / MinutesToTheHour; //determines how long a minute is _secondLength = _minuteLength / SecondsToTheMinute; //determines how long a second is Could be all that. Integer division results in integers, and you didn't supply enough code to know what type ...


1

Normally, once the project is build, if you target windows platforms you will get a dialog to select the resolution at startup. This is optionally since you can disable it and create your own mechanism for managing screen resolution at runtime using the provided API Screen.SetResolution.


0

You can play with the physics material of your sphere (or quad, depends on which one makes more sense) in order to remove the bounciness. If you want to achieve an effect that would not normally be possible in the real life (as in following a moving platform without inertia) you will need an extra layer that will manage this between the two shapes, working ...


0

not sure how your gravity works in unity but in our jump and run we did years ago we checked if the player touched a moving platform and glued him on it unless the player jumps again. you could do this calling the physic system manually until the player touches the platform again or you just add the player in your scene graph to the platform. it was a very ...


2

Your png is most likely not set to be imported as a sprite, and the property you want to use it in requires a sprite (background, checkmark and the others are by default sprites). Click on your png to open up the import settings. The Texture Type dropdown menu is the interesting part here. Set it to Sprite, apply the changes and your sprite-ified png should ...


1

If you have the gameobject with the code attached selected, you can drag the gameobject in the scene using the hierarchy to the inspector. Confusing I know, here is a picture: EDIT: Strike that, this is more accurate: With unity, you can not reference things in the hierarchy from a prefab. You need to somehow add it at runtime. A cheap way to do this is ...


-1

Drag & drop the appropriate gameobject from your scene hierarchy to the property you want to set.


0

OnCollisionEnter(Collision collision){ if(collision.gameObject.name == foo){ //do foo } else if(collision.gameObject.name == bar){ //do bar } }


0

It's going to be a tiny bit of work. To fix this you will need to manage your own cursor in world-space using relative movements of the mouse to move it rather than a screen space cursor. Using Screen.lockCursor (http://docs.unity3d.com/ScriptReference/Screen-lockCursor.html) And Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") ...


0

There is no keyboard shortcuts for moving a selected object around (afaik). What I like to do is change the location on each axis by selecting the gameobject in question and moving it using the inspector; If you mouse over the axis you are working with (for instance: X), you can 'drag' it right or left to increase and decrease that value. This might be a ...


1

Your tilt line is stomping over whatever rotation the drone had and applying a new one. Just like writing: variable_a = 42; will replace whatever value was in variable_a before, the same happens with rotations, unless you use some type of combining operator like multiplication or Lerp. To fix this, you can build a rotation that takes both inputs into ...


1

I usually use a transform hierarchy like this: Entity Object -> Visual -> Collision The "Entity Object" is at unit scale (1,1,1) and contains the rigidbody and whatever the "main script" for a particular entity is. This keeps the inspector clean and means the transform viewed by the main script is predictable. The Collision object is also kept ...



Top 50 recent answers are included