Tag Info

New answers tagged

0

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


0

Unity doesn't support threads. You can use C# threads for some native .NET code but the Unity API is not thread-safe. http://answers.unity3d.com/questions/180243/threading-in-unity.html


1

I don't know how deep u actually get into 3D development, but the error message is quite clear, at this spot, if u understand what is written. To draw something on a graphics card, u need Shaders to define how sth is interpreted on the graphics card to draw it. There is allways a definition for structures u share between ur code and the graphcis card. In ...


0

From here public void Invoke(string methodName, float time); Invokes the method methodName in time seconds. There is a restriction that the method needs to take no parameters and return void, so you should wrap your rotation in another function, like so: void delayedRotation() { transform.Rotate (new Vector3 (0, 0, 1) * Time.deltaTime); } and ...


1

You could create a variable for example called timer of type float and make it equal to the amount of seconds you would like to wait, then in the Update() function subtract Time.deltaTime from your timer variable. Afterwards use if statement to check if the timer variable is equal to zero, if so rotate the object.


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


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


9

In C#, having an instance (non-static) method in a class does not copy the instructions for each object created from that class. Static or not, the data that represents the instructions only exist in one place. The member variables, or state, of each of the instantiated objects do get their own space in memory. When you write a non-static method on a ...


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

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

You can add System.Windows.Forms.Timer to your Form add a label and manage the timer tick event like this private void timer1_Tick(object sender, EventArgs e) { //tt is declared and intialized in form load tt = tt + timer1.Interval ; label1.Text = "Time: " + (tt).ToString(); } finaly to start ...


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

The modifier keys can be combined with OR-bits. You need to use AND-bits to test for the modifier flags since it could contain all of CTRL+ALT+SHIFT (Left AND Right) and even some other modifier keys. For example, if NumLock or CapsLock is ON, the value will never be == to LeftShift. See the documentation for the ModifierKeys. It is also not necessary to ...


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


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


1

Is there any way to recover those codes? Short answer: No. Long answer: Maybe. If you compiled your game, you might be able to decompile it (perhaps with something like: https://www.jetbrains.com/decompiler/ --- your actual mileage may vary). Or depending on what exactly happened to the old file(s), perhaps you can recover them if they were deleted ...


1

Hey I have answered a similar question , where you can populate different tiles as per need, using a 2d matrix to hold the information. Its very basic but you can build on top of it , to suit your needs :) Link:- Generate static 2D Tilemap from array


4

I'd move all those UI constants to a centralized file. It doesn't matter if they are only used in one class or not. The reason is that if you ever want to adjust that type of stuff, it is nice to have it all in one location. You don't want to have to muck with a dozen different classes just because you decided you wanted to change the overall look and feel ...


1

I would make only minor changes to your code: private const string[] _postfixes = { "billion", ... }; public static string BigNumberToString(double number) { int exponent = 0; double num = number; while(num > 1000.0) { exponent ++; num /= 1000.0; } //additional logic for converting here, for your example if(exponent < 3) ...


0

Your code enters multiple Edge colliders and in the if loop only destroys the latest collider object.Check the following image, the collider of previous line still exist as child of the line game object We need to delete each and every child in the Mouse button down event , which will fix the issue. if (Input.GetMouseButtonDown(0)) { ...


0

I have faced this problem earlier.This is because the "Generate Mip Maps" option is on. You need to deselect that option and apply the changes to the sprites. Mip Maps are pre-calculated, optimized sequences of textures, each of which is a progressively lower resolution representation of the same image. They are intended to increase rendering speed and ...


0

You can use Input functions to detect these actions. Following code shows how you can achieve it and I have commented the events when they are true. void Update() { if (Input.GetMouseButtonDown (0)) { //Touch Begin - True when the finger touches the screen //Play animation for chicken squat } else if(Input.GetMouseButton ...


1

I am afraid that the effect which you desire won't be able to achieve through Trail renderer. I had once accidentally achieved it while playing with multiple cameras. What you need is to stop the camera from clearing the render buffer before drawing a new frame. So that the cross at last position remains as is and the new cross gets drawn on top of it . This ...


0

ONE method could be using an object with a particle system. Manage the particle system the right way , controlling it by script, spamming ONE particle based on object moviments. Use the cross ad particle texture..


0

In order to do this you need to simulate inertia. This is how I would recommend doing it: class Ship { public Vector2 Pos; //Current ship position public Vector2 Vel; //Store current velocity as a vector public float Rot; //What direction the ship is facing in radians public float Accel; //Maximum acceleration public float MaxSpeed; ...


1

For anyone interested, my problem was that the prefabs were instantiated as part of an Awake() call, which evidently makes you prefabs invisible. Moving the instantiation to a Start() call fixed my problem.


1

You can basically start leaning to program by making games. To learn game-specific programming knowledge you must make games. There is no grand preparation ceremony you must complete before you can make games. Like any other skill, it's all just practice and repetition. Make games. Make lots of little games. Don't start with a big project or grand idea. ...


0

For getting all the colliders which are below the touch position , we need to use the RaycastAll function. This returns an array of hits from which we can determine the GameObject which is at the farthest distance from the camera. Also take care of the situation where no objects where detected, to avoid the null reference error. void Update() { ...


0

You should proceed in the following way 1) Get the input mouse position convert it to world co-ordinates Vector3 direction = Camera.main.ScreenToWorldPoint (Input.mousePosition); 2) Now calculate the directional Vector3 form anchor of the hinge joint to the input mouse position. Vector3 diff = direction - Anchor.transform.position; 3) The last step ...


1

In my opinion the best is start with a good AI layer that uses a state machine approach (here and here). Making it simple, the current state AI evaluate some inputs, make a decision and eventualy jumps to a new state. The movement and animation layer relay on actual AI state to do their stuff


1

I'm not experienced programmer, but as for me, I try to divide as much logical parts as I can into different scripts. For ex, for the character you can use something like MVC, model-view-controller pattern. The point is that one script processes user input and communicates with tho other parts which are responsible for animations and actual movement. In ...


0

To detect the direction that your player is facing you can use transform.forward as a vector3 value .


1

To determine the cone you should create some variables like AttackLength, FieldOfViewAngke and get enemy component to determine enemy position lookDirection = enemyPosition - player.transform.position; lookDirection.y = 0; attackDirection = Vector3.zero; float angle = Vector3.Angle(lookDirection, transform.forward); if (Physics.Raycast(enemyPosition, ...


0

I think you will have a very similar stuff, compared to this tutorial. You will instantiate prefabs in each tile position. I would create prefabs of tiles based on functionality: Ground Tile Prefab, WaterTile Prefab, etc. Each one with options to activate/deactivate game Objects, to change the looking, for example. You rather use something with a little bit ...


1

Its actually very similar to the way it is done in XNA , only a few changes in the syntax and loading approach. Here is the most basic way in which it can be done. You can build on top of it as per your needs. Before we start, we need to make some tile prefabs and store it inside the resources folder. Lets define some variables, and initialise them some ...


0

When using Unity 5 and the Standard shader you need to use "_EmissionColor" rather than "_Emission" to set the Emission value.


0

The problem with the collision was that the edge collider points were not being set properly. Instead of setting individual points you actually need to supply Vector2 array of two elements. This is always the case in C# , in javascript it works fine. As the start and end points were not set , the collider was taking default 0.5 co ordinates. You can see in ...


3

The problem your having is that motion in games, as smooth as it might look, is better seen as a series of short teleportations. So, since distance is an unsigned value (always greater than zero), your car is just teleporting right past the absolute distance of zero. That causes the check to never go off. You have 3 options: You can add a margin of error ...


2

If you need a safe version of @VB_overflow's answer, you could do this: MonoBehaviour unit = (GetComponent("Unit") as MonoBehaviour); if (unit != null) { unit.enabled = false; } else { Debug.Log("<color=red>Error:</color> Unit behavior not found, can't disable"); } Here's another version using strong typing based on a comment from ...


0

You could create a public class of type your script name and then just use this variable and .enabled = false.


7

Please check solution described here For your case it would be : (GetComponent("Unit") as MonoBehaviour).enabled = false; Warning this will crash if the "Unit" component is not deriving from MonoBehavior (if this is a script you wrote, it should ...) EDIT: The solution proposed by Lohoris in comments is much cleaner and faster, and actuall the official ...


0

You need to use camera faced billboards in order to solve this issue. Which means that you need : To use a 3D quad to display those textures (which you construct by code) To give this 3D quad a 3D position, and a 3D size To orient this 3D quad towards camera at each frame, either by code or in its vertex shader Example to construct a billboard here And ...


0

It looks like you can use the MarshalAs attribute like so [StructLayout(LayoutKind.Sequential, Pack = 16)] public struct cb0_t { public Matrix mWorld; public Matrix mView; public Matrix mProj; [MarshalAs(UnmanagedType.ByValArray, SizeConst=2)] public Vector4[] vLightDir; [MarshalAs(UnmanagedType.ByValArray, SizeConst=2)] public ...


0

There are multiple ways to move your object in the game world. You can set the transform manually (method 1), translate the object from it's local coordinates (method 2), or add a force onto your object's rigidbody (method 3). using UnityEngine; using System.Collections; public class Jump : MonoBehaviour { private Rigidbody rb; private float ...



Top 50 recent answers are included