Tag Info

New answers tagged

0

You need to tweak the shader file. Most probably there will be calculations based on the z axis. You need to take out all the z axis consideration from the calculation. For Example:- o.pos.xy += offset * o.pos.z * _Outline; Change to o.pos.xy += offset * _Outline; As every shader is different, I don't know if it will work for you, but it definitely ...


1

I have faced similar problem before. I am pretty sure that co routines won't help you reduce the lag. Multi threading will be a proper solution instead of co routines. But apparently I didn't use either of them. My game had finite predefined pool objects. So instead of instantiating them, in the editor I made a parent game object named Pool and made all the ...


0

You have set the render mode of your UI canvas to "Screen Space - Overlay" or "Screen Space - Camera", which means it is always in front of the current main camera. To get it out of the way, just disable the canvas. When you want to keep your design which appears to treat the menu like a 3d object which is shown by putting it into the camera view, switch ...


2

You can attach the sprite to the child of the main game object which handles the collision detection logic. Whenever you want to flip the sprite just do it on the child object leaving the main object as it is. This way you can achieve your desired result :)


0

@MLM Great tutorial/example I have one little question... related, I think. What if I want to form some sort of polygon formed by 3 or more points? For example, if I have 3 points, I've used GL.Vertex (x,y,z) 3 times, one for each point, but I only get one line (from A to B). My question would be, do I have to use GL.Vertex (in this case) 6 times? A and B, ...


0

I had this problem too but im unsure now what the fix was. Are you using the community or the pro version? You may have to get the community edition, which is free and has no trial period. You should first try disabling your firewall and antivirus though and do the update again. Your pc may be blocking the update process. This seems more likely to me. ...


0

Fixed by changing my C# script: private delegate string ReadData(); private ReadData dataReader; #if UNITY_WEBGL && !UNITY_EDITOR [System.Runtime.InteropServices.DllImport("__Internal")] private static extern string ReadFromDom(); #else public TextAsset testData; private string ReadTestData() { return testData.text; } #endif void Awake() { ...


1

If it's a 2D game and you want to clip to some rectangular area, why not just use an overlay with a cutout for the area you want exposed? There would be no runtime tests required. Just place all the tiles, then place your mask layer over top. This is the same sort of technique that is used for most HUDs. Eg. A border around the edge of the screen. The ...


2

What your are looking for, is called scissor test in OpenGL/Direct3D vocabulary. But unfortunately you don't have direct access to that feature in unity. I've been looking for a solution to same problem a few weeks ago, and I came across people suggesting to use multiple cameras with different render area to simulate this behavior. Here are some articles ...


15

I haven't looked at specific implementation of A* by Aaron but with a normal A* you could include the 'block tower' as passable terrain but update the heuristic so that the 'cost' is much higher than a normal tile (so that AI will evaluate whether it is easier to destroy the block and continue or simple go around via the path that is not blocked). Then you ...


0

If what you are looking for is a sort of taunting tower you can add a collider to it set as is trigger and when the minions enter the trigger they are just scripted to attack the tower. If you want the minions to attack the towers only when there aren't alternative paths, then when the path is blocked and the A* is called to calculate another path if it ...


0

The arguments you've passed to Lerp here do not make sense. It looks like partly a misunderstanding of vector and scalar quantities, and partly a misunderstanding of what Lerp does. The third argument of Lerp is a blend weight, controlling how much of each of the first two parameters to mix together. When passed a constant zero as you've done here, it ...


0

As far as I know, no. Prefabs are editor side only. By the way there is no need to make a prefab since you can build a generic GameObject and customize via script adding components and loading resources like sprites from file. For Example void Start(){ Sprite loadedSprite = Resources.Load("your_sprite_path", typeOf(Sprite)); GameObject go = new ...


1

The problem is that you are running your mouse coordinates through Camera.main.ScreenToWorldPoint twice. var v3 = Input.mousePosition; v3.z = 16.0f; v3 = Camera.main.ScreenToWorldPoint (v3); Vector3 worldMousePosition = Camera.main.ScreenToWorldPoint (v3); Deleting the 3rd line will help. When you also have the problem that you are ...


1

You need to create a vector pointing towards the mouse -> Subtract the position of your cannon from the position of your mouse. vector2 dir = mouse.position-cannon.position Then you get the angle from this vector by using this formula if y is up and x is right angle = arctan(dir.y/dir.x) // or use atan2(y,x) Now you have the total angle that you need ...


0

I cannot add just a comment because of missing reputation so I write it as answer but be aware this is not a tested answer. You apply the transform of ur obstacles parent after initiate. So maybe it's because after the initiate of the obstacle the player collider trigger fires up, because the actual position of the collider is at the players position at ...


0

If this should be a general possibility to change textures of objects dynamically, then I don't suggest to use a script on each object. May think of building ur own component, that loads a texture and looks every draw if has to change the texture. If this should only be for a few objects, about 1-10 in ur scene it's totally ok if u want a quick'n dirty ...


1

You can do some cool things if you allow the tiles to overlap a little and then interpolate bits that overlap. For the parts that overlap you need to calculate each tile's contribution (weight) to the overall height which I'll refer to as H(x,y). Then when you sample H(x,y) you find each tile that overlaps that point and sum the weighted local heights of ...


3

You might consider something like Wang Tiles. The idea is that you have a predetermined set of edges for your tiles. You can randomly generate tiles, still, so long as the edges match. For example, you might have 4 possible sides: A: Low terrain B: Mid terrain C: High terrain D: Water You can generate the first tile by randomly choosing the 4 sides. ...


1

There are two options for you. 1) Keep the image component on the button with a sprite, then set the transparency/alpha on the color to 0. 2) Write a separate script that you attach to a gameobject (Or image/button) that implements the Unity event interface: IPointerClickHandler and inherits from UIBehaviour. IPointerClickHandler is the interface Buttons ...


0

pick your instantiated prefab, say GameObject go = GameObject.Instantiate(yourPrefab) as GameObject; and get for example a sprite Sprite yourSprite = Resources.Load("sprite" typeOf(Sprite)); and change the prite go.GetComponent<SpriteRenderer>().sprite = yourSprite;


1

If the sprites are in your Assets/Resources directory, you can load them programmatically as follows: Sprite[] spriteSheetSprites = Resources.LoadAll<Sprite>("spriteSheetName); This will yield a Sprite array containing all of the sprites from your spritesheet, indexed by their order on the sheet. A requirement to use this is that the image's ...


0

i would, in order: create an instance of the object you want to drag set its collider to is trigger change its rgba channel values to give it different color/transparency on mouse button release check if overlap with OnTriggerEnter 4.b. you can optionally if objects overlap change color from blue to red, for instance if they don't then move the original to ...


0

http://docs.unity3d.com/ScriptReference/Random-insideUnitSphere.html If you need something more complicated than a sphere, or box, you will end up creating your own randomize logic by hand. You could set values in the inspector for example, bound values. You could set up possible colliders, then randomize the position, and test it against these ...


0

This is achievable , what you need is Unity water and some script to simulate buoyancy. You can find the script in this link:- http://forum.unity3d.com/threads/buoyancy-script.72974/ Note:- You might also need to use some particles or mesh to fill the volume of the water. As unity water is restricted only to the surface and not the entire volume :)


1

From here, this can be used to calculate the volume of an arbitrary 3D mesh. public float SignedVolumeOfTriangle(Vector3 p1, Vector3 p2, Vector3 p3) { float v321 = p3.x * p2.y * p1.z; float v231 = p2.x * p3.y * p1.z; float v312 = p3.x * p1.y * p2.z; float v132 = p1.x * p3.y * p2.z; float v213 = p2.x * p1.y * p3.z; float v123 = ...


1

You can do this if you use Sprite.Create You would typically use this along with a Sprite Atlas, as setting the Rect properly without one would be pretty tedious.


0

Pick a random point on the map which is not blocked. Then Calculate a path from the current position to the destination using a stock route finding algorithm like Dijkstra's Algorithm or A*. When no route can be found, then the random destination is either unreachable. Pick another point in that case. To avoid a deadlock in case there is no possible move ...


1

You may be interested in Nodal Pathfinding. The concept is similar to placing waypoints, except you generate these way points on top of your world. The waypoints are then used with an A* pathfinder, to determine the optimal path. Have a look at the blog here: http://www.jgallant.com/nodal-pathfinding-in-unity-2d-with-a-in-non-grid-based-games/ Another ...


1

Use waypoints in your map. The enemy AI in "patrol" state chose a random visible waypoint as target. Reached the waypoint repeat step 1. (eventualy excluding current waypoint) If you don't want to place manualy waypoints you can generate them at the corners via script : here follow an example: cons: the enemy will patrol in straight lines from ...


0

if I understood : "Now I have an angle in eulers and I want that the ball goes to the direction of the angle. But how I calculate it?" You need : dirx = cos(angle); diry = sin(angle);


0

You don't need your Direction() function. It also doesn't return euler angles. Unity's Vector3 class has all the functions you need. See the code below. Vector3 pos1; // start position Vector3 pos2; // click position Vector3 moveDistance = 3.0f; // move 3 units in the calculated direction Vector3 delta = (pos2 - pos1); // delta is the vector difference ...


0

This issue may be caused by other problems also. 1) Try loading the scene with Application.LoadLevel(Application.loadedLevel); some times the loaded level name gives problem if the build is a split binary. 2) Make sure your adb log cat limit is set to over 100k (My mobile OS shoots lot of internal logs due to which unity logs just disappear form the list) ...


0

In the future, you could have easily found this with a search. It has been asked many times before and is a pretty simple thing to do. You will usually not get many good answers (or any at all) if you dont search some first =-) However, with that said: IIRC, if both of your game objects have colliders attached to them and you catch that collision, you can ...


0

The GUI and EditorGUI drawing functions seem to not be the best solution for the level of drawing precision that I need. They seem to be influenced by GUIStyle, which has dozens of properties that may interfere with positioning. The better solution I found was to use GL combined with the built-in shader Hidden/Internal-Colored to get the screen-space ...


2

Try turning off backface culling. In your shader, put "Cull Off" in the "SubShader" section.


0

i found that it must be the wheel collides or some other child causing the issue anyway here is the code i now use void OnTriggerEnter (Collider obj){ motor mObj = obj.transform.parent.gameObject.GetComponent<motor>(); if(mObj != null){ //code here Debug.Log("mObj not null"); if(mObj.enabled == true){ ...


0

Make the following changes to the code. motor mObj = obj.gameObject.GetComponent<motor>(); if(mObj != null){ //code here Debug.Log("mObj not null"); }else{ Debug.Log("mObj is null"); } On trigger will only work if the game object to which this script is attached have a collider. It won't work if only ...


0

I am not sure about the 2 pixel displacement , but try putting the camera in orthographic projection this might fix the problem.


1

You could disable the gravity on the Rigidbody and then just make gravity yourself by writing a script and using GetComponent<Rigidbody>().AddForce(-Vector3.up * Time.deltaTime * YOUR GRAVITY VALUE) and just change YOUR GRAVITY VALUE when ever you want the object to be slowed down.


0

Just to clarify, applying gravity to a specific rigidbody will not effect everything in the scene. If it does, then you have a larger issue about to come. Calling a reference to the rigidbody attactched to an object and adding gravity * Time.deltaTime will increase gravity until the player touches back down. At that point I would decide a max gravity value ...


0

Parent the gun to the player not the camera. The camera movement is changing the transform of the gun. The capsule for the player still tips forward and backwards so parenting it to the player will alleviate the issue. Otherwise you can code a fixed transform that only allows for verticle and horizontal transform change instead of a forward transform change ...


0

The Unity Camera will always fit to the height , and it will scale its width towards left and right. You don't need to do anything to the camera to adapt it to 960x544. For testing purpose you can add a custom screen size to see how the actual game will look like. Go to Game window and select the drop down beneath to add a custom screen size. Reference ...


0

For simple shadows you can create a material and select the shader as Sprite>Diffuse , this will enable shadows on the sprite. If you are looking for more than just shadows i.e. adding normal maps and other cool stuff, then check these two links give below :) Writing a SpriteLamp Shader in Unity Kencho's dev blog


1

Yes it is possible to export Unity terrain as an obj file to use in other game engines :) Follow this Link :- TerrainObjExporter


0

You could try and check if the distance between two objects is increasing or decreasing or you can use an infinite raycast and check the object it hits.


0

Unity doesn't display 2D array in the inspector. For this we need to add our own Editor script to make it appear in the inspector and make it editable . Fortunately there is already a tutorial available on how to achieve this functionality . Link:- https://www.youtube.com/watch?v=uoHc-Lz9Lsc&feature=youtu.be Download Link for the code :- ...


0

You will need to create a custom property drawer. You will also need to create a custom serializable class for your solution dataset. I may be wrong, but I don't think you will be able to assign a property drawer to a generic list type like you have. ...


0

https://www.youtube.com/watch?v=bh9ArKrPY8w You have options. You can either use a bunch of primitive colliders (which will be most efficient but also the most time consuming and tedious option), or you can use a simplified mesh created specifically created to be used as a collider. The above video goes into more information about colliders and goes over ...


0

You can use Mecanim "Triggers" to start the Shoot animation state. The trigger will reset itself to false in the next frame, so the shoot animation will play only once. Then from shoot animation make transition back to idle pointing gun state and the condition should be exit time. Example :-



Top 50 recent answers are included