Hot answers tagged

5

The best way to do this depends on a few things. I'm going to assume the following - if any of these are incorrect, please let me know and I'll update my answer: You want the closest enemy that is anywhere to the right of the player within a certain range, even if it is at a different height You want true distance, not just the one that is closest in ...


4

It has been a while since I've touched Unity, but this should get you in the right direction. Assuming A, B, and C are objects, and we want to see if B or C are closer to A: var BtoA = (B.position - A.position).magnitude; var CtoA = (C.position - A.position).magnitude; // Assume B should return if distances are equal if(BtoA <= CtoA) { // B is ...


4

It looks like you have 2 halves to 2 different solutions for this, so I'll explain both possible solutions and let you choose the one that best suites your needs Solution 1 Initiate a bullet instance and remove the health from enemies the bullet hits In your GunScript fire a bullet when the mouse button is down (this is half the code you already have) ...


3

Alternatively to SP's suggestion, you can also add events to the Mecanim animator now. Take a look here: Then you can script it in, if you prefer this method. I have personally not used this feature yet, I just noticed it. There doesn't seem to be much information in the docs about it yet.


3

Libgdx is a free game library that supports java and can be deployed to Android and iOS. You will definitely be able to use a lot of your existing code and, depending on how you implemented your Android game, you may even be able to convert many of your draw calls to the Android canvas directly to draw calls in Libgdx. Libgdx definitely has a steeper ...


2

There are multiple ways to test a game, two most used are: unit and integration testing. For unit testing you're testing the inner workings of the game, without actually running it. You can do this for specific modules which have dependencies abstracted away (e.g., logic that computes the Quest XP you get, based on a given set of factors; whether a given ...


2

I had issues with PlayerPrefs() on Tizen device. Same game Worked great on Android and iOS. It's good practice using XmlSerializer or Binary Serialization. They have better control when dealing with lots of data like in your case.


2

So long as your 'Text' object contains a Text component, this will work as expected. You may have replaced the Text component with your TextController script, or it was removed some other way. Alternatively, you could change your script as follows: using UnityEngine; using UnityEngine.UI; public class TextController : MonoBehaviour { public ...


2

If you just want bumps and scratches, you can do things like use effects and deform the vehicle mesh and you wouldn't need a large collection of objects. Assuming you want to have bits fly off in a super realistic fashion and have it look awesome, then I think the easiest way is to do what you already suggested. Have a collection of objects that can detach ...


2

You can put the particle object as child to the main object and animate enable/disable the child in the animation tab. It's editor only.


2

Ok, this is how I did it. Set asset serialization mode to force text Create a empty animation clip containing the Image.sprite property. Open up the new and old animations and copy everything bellow -curve: and pptrCurveMapping: from the old one to the new one. Enjoy your new animation that works with UI images.


2

All the left enemy are in lower value in x-axis position. Objects on right side are on higher value. Subtract main character's x value from enemy's. Positive results are for enemies at right side.


2

In your RespawnPlayer() method you are loading a scene at first. Then checking current position, then translating the player to the checkpoint. Upon loading a new scene, everything resets. In RespawnPlayer() after second line execution, the level manager restarts from Start() ignoring the current checkpoint and player translate codes in RespawnPlayer(). In ...


2

Make the gameobject face towards is velocity vector (or its last non-zero velocity vector): float angle = Mathf.Atan2(rigidbody2D.velocity.y, rigidbody2D.velocity.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.AngleAxis(angle, Vector3.forward), rotateSpeed * Time.deltaTime);


1

An easy way is to use GUI. Have a big square about 16x times the size of the screen with a circle in the middle of it. This is so if your playing on the TV, you wont see the stuff behind the background.


1

If you just need it once, I'd suggest you pick up some basic knowledge of a modelling tool. It's very easy to do in Blender: Delete the cube that you start with by pressing DEL. Create an UV Sphere primitive. This will create a sphere with radius 1.0 (Note: In the lower left corner you can edit the properties (segment/ring count, radius) of the sphere ...


1

Assuming your enemies all have colliders, could you not simply fire a 2D Raycast https://docs.unity3d.com/ScriptReference/Physics2D.Raycast.html in a straight line to the right of your player and return the GameObject of the first collider it hits?


1

The thing is that with your list you dont know if the element is a weapon or a apple. It's just a GameItem. To be able to use the weapon specific properties you need to retrieve the element and cast it back to a Weapon. For example the update in inventory manager will look like this. void Update() { if (Input.GetKeyDown("a")) { ...


1

This link looks interesting and provides almost that what I need, maybe it can help somebody too http://forum.unity3d.com/threads/animfollow-active-ragdoll-is-now-free-to-download.220812/


1

While I don't know for sure what these two games do, this is how I would do it: Have a Canvas set up with a child GameObject (which can be a prefab) holding all Game Over UI elements. This starts as disabled In the UI GameObject have a script which listens to OnEnable and fills out the relevant info (stats etc) Have a Game Controller that controls the ...


1

If I would implement it in Unity I'd do a dedicated scene with a GUI to show whatever is needed. So in the main scene I would have some script not destroyed on load of a new scene (with DontDestryOnLoad(GameObject go) method) which have all the infos you want to display at the Game Over stage. You could also handle it in a whole scene with variables to ...


1

Following Unity documentation at the moment this is the following supported .NET lib and their versions. http://docs.unity3d.com/410/Documentation/ScriptReference/MonoCompatibility.html it has been mentioned several times that once Unity5 gets stable they will start adding more compatibility with newer versions.


1

So, what we have. Developer from the VS Tools for Unity team said that it is one of their most voted feature requests. And it's surprisingly not trivial to fix, they are working on it. However, I found some script which can use.. I found it on russian unity community. Great thanks to DbIMok. Also he posted this script yesterday on forum.unity3d.com ...


1

You might have some success checking the Collider2D.IsTouching method in your OnTriggerEnter. void OnTriggerEnter2D(Collider2D col) { if (weaponCollider.IsTouching(col)) { /* Weapon */ } if (sightCollider.IsTouching(col)) { /* Sight */ } } IsTouching is polled against the last physics update so it should be pretty light weight. However, if your ...


1

If I understand your question correctly this can be done using a bit of vector math. I've created an example in Javascript so please keep in mind that many of the mathematical operations I'm doing here can be done in Unity really easily using the built-in classes and methods. The ball will follow your mouse when you hover it over the window. I recommend you ...


1

See the trigger pressing input. If it's pressing keep the value in a Boolean. The code will be like: if(pressing_trigger) //trigger values are [0-1] so pressing_trigger is true when trigger value is greater than 0 (zero). { //your acceleration code } Go to xbox/ps trigger setup


1

Yes, because PlayerPrefs are VERY unsecure. If you get into the habit of using PlayerPrefs to store data, even for games where it doesn't matter, then you'll run the risk of doing it when it does matter, such as with an online multiplayer game or some such game where cheating would make a big difference. The reason it matters is because they are extremely ...


1

It is up to you, but on android at least it is very easy to reset these things on your phone. Most of the time it is best to save things that you do not want to lose externally so that the user cannot manipulate or delete it. I am not positive how easy it is to do on iOS, but on android all you have to do is go to the app in the application manager and clear ...


1

I dug into this some more and have come to the following understanding. I'm open to be corrected though, so if anyone knows more, please chime in. For now though, this is what I think is going on. rigidbody.inertiaTensor contains the diagonalized elements of the inertia tensor or the principle moments of inertia. These correspond to some internal symmetry ...


1

It seems to me that what you're doing has the correct basic form. But I think rigidbody.inertiaTensorRotation needs to be taken into account, though I'm not 100% positive on this either. I would argue though, that it must be that rigidbody.inertiaTensor is diagonal with respect to some arbitrary coordinate frame, while rigidbody.angularVelocity is most ...



Only top voted, non community-wiki answers of a minimum length are eligible