New answers tagged

0

private Animator animator; // Use this for initialization void Start() { animator = this.GetComponent<Animator>(); } // Update is called once per frame void Update() { var vertical = Input.GetAxis("Vertical"); var horizontal = Input.GetAxis("Horizontal"); if (vertical > 0) { animator.SetInteger("Direction", 1); ...


2

You are only checking th i-th bullet with the enemy of the same index and not with every enemy there is. You should do something like this for (int i = 0; i < Bullet.Bullets.Count; i++) { for (int j = 0; j < Enemy.Enemies.Count; j++) { if (Collisions.IsColliding( (int)Bullet.Bullets[i].position.X, ...


0

If you have several platforms connected in Unity your character might sometimes, (not always) slow down/stop. There are 2 fixes that might work for this : 1. Circle Collider If you have a box collider on your moving object/character, the corners of the collider might collide with the corners on the connected platforms, causing the object to slow ...


0

Try changing your assignment to debug[id.xyz] = 1;


0

I solved the problem. i removed all playstore plugin from my project, then i select Edit -> Reimport all. then I import admob plugin. them in AndroidMainfest.xml i changed "android:value="true" to android:value="false" ". <activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="@string/app_name"> <intent-filter> ...


1

I'll throw my singleton into the mix. It checks off all four of DMGregory's criteria (see his answer). This has a lot of stuff that may not make sense. It is just covering Unity specific corner cases, and persists between scenes. It is tried and tested, and the most current version can be found on my Github. Enjoy! Usage is by having your script extend this ...


2

As your desired image reflects that you want it in 2D, so I have modified your current script which would draw a path from your given Game Object, decided start position, mouse or finger position would be the end position. Other than that you can specify number of elements should be drawn on the path. Well, have a look and give it a try. Comments will also ...


0

yeah, thank you, But still the problem. ... here, my code: https://drive.google.com/open?id=0B_j9kxE7xxc2S0RaQkx1Ty1waVE the "Tableau X.txt", "Tableau Y.txt" and "Tableau Z.txt" contains the x, y,z datas for each profiles.


0

You may have had an issue with your tile-sheet. The question now displays a properly framed one. It looks like at 6*15 tile sheet. So... Instead of using a float tileSize, which has the same value for the x and the y axis, I would suggest you use a vector2 instead: // Keep in mind that my c# is not good so you may need to adjust the syntax of the code, ...


1

In C# when a struct is accessed via a getter (like transform.position), the compiler won't allow you to modify a member, because it has no sense to do that, because a getter of a struct return a brand new struct that you have to reference first. If you don't your brand new struct will stay inaccessible...


0

You assign the object you find to the wrong reference; this should do the trick: GameObject Particules; void Start() { Particules = GameObject.FindWithTag ("Particules"); } void OnTriggerEnter() { Particules.AddComponent<Rigidbody> (); }


0

While Draco18s mentioned in comment about good practices. But one more thing is considerable is that you declared Particles on class level. Then you are creating new one and assigning in the scope of Start, which will destroy as soon as pointer leaves the Start braces. So in OnCollisionEnter your Particles object is still empty. Try to remove declaring in ...


2

So upon further inspection your problem actually has nothing to do with coordinate system conversions. This could have been made more clear by not naming your axial coordinates X and Y but rather Q and R. The problem you're actually having is bad loop conditions. The original code sample produces delta q's and r's which you try to convert, in your for loops, ...


0

You want to create a flat plane in 3D for this, set texture sampling to point sampling and use Matrix.CreateLookAt for the view matrix. I suggest you read up on what the world, view and projection matrices are and what they do.


-1

To answer all your questions: The two languages supported by unity are currently javascript and c#. In unity 4 was a 3. one, boo, but like 5% of the developers used that language, so they removed it to be able to focus on other aspect of the engine. javascript Don't let the name confuse you, this is really far from the pure javascript. Unity provides some ...


0

Expanded post on comment:"JSON is just a means of storing text information right? Why not just hold a path to the sprite in the JSON file? Then whenever you obtain the information in the JSON file, call Resources.Load (jsonPath); ?" The JSON language cannot directly load Sprites into Unity3D. However, as JSON can deal with strings, we can quite easily hold ...


3

The short answer is that the standard perspective projection has a side effect of focusing Z resolution near the camera, which is actually beneficial. A perspective projection turns out to be linear in 1/Z rather than Z, meaning that there are very large changes in Z near to the camera, but smaller changes as the distance increases. Here's an article ...


5

As Vector57 noted, the problem is you are using the wrong coordinate system. The algorithm described is meant to be used with cube coordinates, which have x, y and z components: This may not be obvious from the algorithm's pseudocode, but that's because it's a simplification of this: var results = [] for each -N ≤ dx ≤ N: for each -N ≤ dy ≤ N: ...


2

Another option might be to split the class into two parts: a regular static class for the Singleton component, and a MonoBehaviour that acts as a controller for the singleton instance. This way you have full control over the singleton's construction, and it will persist across scenes. This also lets you add controllers to any object that might need the ...


2

I'd just like to add that it may be useful to call DontDestroyOnLoad if you want your singleton to persist across scenes. public class Singleton : MonoBehavior { private static Singleton _instance; public static Singleton Instance { get { return _instance; } } private void Awake() { if (_instance != null ...


7

Here's a quick summary: Create object Removes scene Global Keep across if not in scene? duplicates? access? Scene loads? Method 1 No No Yes Yes Method 2 Yes No Yes No PearsonArtPhoto No Yes Yes ...


0

I'd recommend against finding GameObjects by name (using GameObject.Find or transform.Find as suggested in the existing answers) whenever you can avoid it. In my experience this tends to lead to brittle relationships between scripts that are easy to break accidentally, and other more exotic bugs. The most reliable method, if you have a script that needs to ...


4

It depends, but usually I use a third method. The problem with the methods that you used is that in the event that the object is included to begin with, it will not remove them from the tree, and they can still be created by instantiating too many calls, which could make things really confusing. public class SomeClass : MonoBehavior { private static ...


0

There are multiple possibilities here. You can use the static function GameObject.Find() to find a gameobject by name in the entire scene. However, this function is a bit slow so try to call it only once. You can also use the non-static function Transform.Find() that will only search in the childrens of the transform. Transform.FindChild is deprecated and ...


0

It is because you brought Canvas itself and you are trying to access gameObject's properties. So for that try, mainmenu.transform.Find.......


0

This is the best solution I found to this problem: I splitted the table model to two separate models. One contains only the table "bed" (not sure if the name is right - I mean the table top / plate). The other model has all the rest, which includes some geometry drawn over the table top (this is a kind of a billiard table actually, so it has some ...


0

Nope. http://answers.unity3d.com/questions/653245/how-do-i-create-a-light-that-emits-darkness.html Suggests using thick, black fog instead. http://forum.unity3d.com/threads/is-black-light-possible-in-unity.92378/ Suggest using a projector to project a black texture or writing your own Light component.


0

Actually Unity create a default material for meshes if you don't assign any material explicitly. And the Rendering Mode of that default material is set to Opaque that prevents you to play with transparency. Although _Color property is declared in Standard Shader. Means your code is right. Well, it's totally another topic. What you can do is to create your ...


1

Replace if(Input.GetKeyDown) (KeyCode.Space)) { rigidbody2d.velocity = new vector2(0,jumpHeight;) } with if(Input.GetKeyDown(KeyCode.Space)) { rigidbody2d.velocity = new vector2(0,jumpHeight); } It seems like you are missing some of the most basic concepts of C# syntax. Doing some basic C# tutorials (not ...


0

First, @peethor is correct in the comments. Your semi-colon is in the incorrect spot. (Should be at the end of the line. Also, your if statement syntax is incorrect. Second, you need to get the component of the RigidBody2D before trying to set the velocity. (Make sure that the component exists on the same gameobject that this script is on. If not, you'll ...


0

Is the semicolon after "jumpheight" just a typo, or is that really the problem. More information needed otherwise.


0

Let's say you've got a set of variables that stand for your save game entity. You can, for example, create a class within your save manager script like this: [Serializable] public class GameSave { public DateTime lastMod { get; set; } public int games { get; set; } public int coins { get; set; } public int bestScore { get; set; } } Don't ...


0

You can do it simply by using DontDestroyOnLoad Add your manager Game Object in splash screen. Attach all the scripts you want to it. In any one script call DontDestroyOnLoad in Awake. void Awake(){ DontDestroyOnLoad(gameObject); } This game object will last through out the game.


0

Then I'd suggest to play with velocity directly. It'd be easy to handle. I writing an untested code for doing the same but with velocity on Space Bar. Give it a try if this would help you. Rigidbody _rb; Vector3 _velocity = Vector3.zero; float _speed = 0.1f; void Start () { _rb = GetComponent<Rigidbody> (); } void Update () { _rb.velocity = ...


1

The relations of your data-model (club has players, competition has participants...) are part of the model. Trying to represent these connections between entities in the controller will likely lead to a complete duplication of them. It is often a good idea to try to keep the connection one-sided (either the club has a list of players or the player has a ...


4

This code is converting from premultiplied alpha: Expanding one of the assignments by substituting for divAlpha: var r = (byte) (color.R*(0xff00/color.A) >> 8); which on rearrangement of the multiplicative terms becomes var r = (byte) ((color.R*(0xff00) >> 8)/color.A); which in turn simplifies to: var r = (byte) (color.R*0xff /color.A); ...


0

There are multiple things I can think of that could be causing you problems. Here are some things to look at: If your rigidbody is set kinematic, setting velocity will have no effect. Add debug statements like those in the code below to see what is or isn't working as intended Try removing the boundary checking statement to eliminate that as a potential ...


1

So here's the deal with 9 patches (or as @hamza-hasan called them in the comments "9 slice scaling"). Either way the concept the same. The concept is pretty simple. Slice your source image up into 9 sections as shown in the image below. For reference I've drawn 4 red lines to represent how the texture might be sliced up to create the 9 patches. I've also ...


1

I found myself that to speed up my nbody. Instead of iterating through all of i & j. With i=0, i++, j=0, j++ and setting the force of object i to fG. I can use i=0, i++, j=i+1, j++ and set the force of object i to fG and object j to -fG.


1

Try material.SetColor ("_Color", myColor) or material.SetColor ("_TintColor", myColor); That changes the values directly on the shader material. I hope that helps!


1

Well, to achieve your requirement, I have another work around, place these lines of code in very same script. ... public float _cameraRotationSpeed = 0.1f; ... void Update () { ... ... if (Input.GetKey ("z")) { tiltCamera (true); // Replace parameter with bool } else if (Input.GetKey ("x")) { ...


1

This isn't recommended practice at all. While there are ways to use built in resources, the images aren't defined, and might have issues if you choose to use them. What a much better way to do it, and the way that I have done, is to have a prefab defined using the desired format, and instantiate it, rather than attempt to do this all programmatically.


5

So the first thing I noticed was that when you do previousTouch = currentTouch; currentTouch.Clear(); this should also clear previous touch since List is a reference type. The second thing is that there is no space partitioning so your collision check currently runs in O(n^2) as best case runtime. The third thing is that it's weird that you calculate ...


0

Double check in your itunes account if you have added leaderboard id in your version. Like,


0

Make sure the FX folder is a subdirectory of the folder containing the .exe. In this case /bin/debug/FX


1

You can use the property Environment.StackTrace to get the current call-stack, i.e. which method called which method which called which method which called this method. Most debuggers also expose this information in a more comfortable way. This usually gives you a pretty good picture of what chain of events lead to this line being executed. It won't tell ...


2

Whenever a Entity is added to a Entity Controller (EC), this EC registers to ComponentAdded and ComponentRemoved events from the Entity. When a Component is added or removed from an Entity, fire the proper event. The event handler of EC is called, then you can insert or remove the Entity from Systems according to the Components it has at the moment.


0

Something that you could consider is using Bézier Curves. Find some way to determine the points that generate a curve that fits each corner of your race track. Use the function for that particular curve to calculate collision. Here is some more reference for using Bezier Curves in the context of game development.


1

The best solution near me to do so is to attach a small script to every object, that will move your object and handle touch to itself. You can create a script that'd attach to your objects like, Assumptions: I am moving object towards -ve x-axis. You can play around with this. using UnityEngine; using System.Collections; public float _speed = 0.01f; ...


1

Yes, make a boolean variable at the start in Game1. Like this: if (ballStart) { ball.update(); } Next, go to where you get the input from the user and change the boolean to be true once the key is pressed. eg. if (player1keyboardState.IsKeyDown(Keys.W)) { paddle1.direction.Y = -1; ballStart = true; } Hope this helps.



Top 50 recent answers are included