Tag Info

New answers tagged

0

The way I would do this is by having Auth server send token to Client after login along with list of validated Game servers (so that the Client can be sure the Game server is valid). Then the Client would send the token to the Game server, which would then send it to Auth server to confirm that this is the valid client. Login: Client to Auth server: ...


1

Edit: After posting this I realized it's almost the exact same answer given by Ali.S (slightly different but the overall approach is the same.) It started out as something completely different though. This method assumes that all communications are being held over a series of secure tunnels. How you achieve this doesn't matter. I would suggest TLS, but ...


2

If you want to be hardcore about it... public static bool StringComparison (string s1, string s2) { if (s1.Length != s2.Length) return false; for (int i = 0; i < s1.Length; i++) { if (s1[i] != s2[i]) { Debug.Log ("The " + i.ToString() + "th character is different."); return false; { } return ...


1

There are multiple solutions that I can think of, but here is the most secure one: client connect to server. client requests an authentication bridge. server connects to auth server, acting as a proxy between player and auth. server. client and auth server, form an SSL session over this newly formed bridge. using this secure connection over bridge, client ...


0

How about signing a JWT token with a secret only the central auth and player server knows? It lets you sign json, which can be verified later.


1

The client should have a private and a public key. The private key should be what the unique identifier that the client receives from the authentication server. The public key should be also sent to the client. Before the client connects to a game server, it should send a message with its private key and the ip of the game server it wants to connect to, ...


2

I had to solve this issue a long time ago, and all I did was do: One normal collision check. One where I shifted everything up one "world-height" (aka screen height) Shift down Shift left one "world-width" (screen width) Shift right Up and Right Up and Left Down and Right Down and Left eg: if(x + width > test.x && x < test.x + test.width ...


0

Augment your finish line point with a direction vector representing the "forward" direction. Then, instead of: if (Vector2.Distance (finishline.position, car.position) != 0) [...] Do: if (Vector2.Dot(car.position - finishline.position, finishline.direction) > 0) [...] Note, if the direction happens to be aligned to a cartesian axis, say +X, the ...


0

I found a trick for this problem (tested just for the spotlight)! Do the following things: 1) Set the range of illumination to just reach the wall(the strength of the light on the wall will decrease). 2) Increase the intensity as you want and you will see that the light is now illuminating just the wall and don't go through


0

This wouldn't answer the question of measuring the distance but for the scenario that you described, I find that placing a collider as trigger on the finish line and checking OnTriggerEnter in your car would be a better solution rather than calculating the distance. For distance check, Dexyne is totally correct but you could also check using the ...


-1

Update – My bad, as @DMGregory says the value of a distance cannot be negative (and it makes sense). As @Kimserey and I says, you can use a trigger. Probably better in this case and easier to use. when the distance between the car and the finish line hits or goes under 0 I think the problem is your if statement. Your test should be: if ...


0

I have done something like this and works great.. background scrolls from top to bottom. To make black bar disappear add an offset to size of second background initiate() { offset=2 ; bg1=new Sprite(backgroundImage); bg2=new Sprite(backgroundImage); bg1.setSize(width, height); bg2.setSize(width, height+offset); //ADD AN OFFSET HERE YOU ...


1

Coroutines are the best performance-wise. I.e. void Start () { //Starting the coroutine StartCoroutine (Shooter()); } IEnumerator Shooter () { if (Input.GetMouseButton(0)) { //Shoots the bullet Rigidbody bullet = Instantiate (Bullet).GetComponent<Rigidbody>; bullet.AddForce (Camera.main.transform.forward * 10, ...


0

The last time I faced something like this I came at it from a very different direction: I didn't use a global cooldown at all. After a shot was fired I set a reloading timer on that barrel. Every tick the reloading timers were decremented. (Watch out for roundoff errors if you're using floating point--I simply used a certain number of game ticks.) When ...


1

So this doesn't produce exactly the behavior you asked for but I think it might be what you're looking for anyway. This code (syntax not exact as I don't use c#) would allow someone to sustain a fire rate of one bullet per 0.5 seconds indefinitely, but fire bursts of up to 3 bullets at a rate of one bullet per 0.12 seconds. gunBurst=0.12f gunSustained=0.5f ...


4

Your code is very scrambled. You have all your time relative variables inside the shooting loop. and the instantiation code too. Why? Why not simply make it like this : void ShootBullet() { Rigidbody bPrefab = Instantiate (bulletPrefab, transform.Find ("Bullet").position, Quaternion.identity) as Rigidbody; bPrefab.AddForce (transform.up * ...


2

In the frame that bulletCounter become 3, Time.time will be less than gunGlobalCooldown because this line of code: gunLocalCooldown = Time.time + 0.12f; gunGlobalCooldown = gunLocalCooldown + 0.8f; so the boolean canShoot will be set to false, and this if if (Input.GetKey (KeyCode.Space) && Time.time >= gunLocalCooldown && ...


0

You could remedy to this by adding another bool canJump : public void Jump () { if(canJump) { if (grounded) rigidbody2D.velocity = jumpVelocity * Vector2.up; canJump = false; } } So when you are clicking, the Jump() method will run the jumping loop one time.After this code, you will need to set the canJump ...


0

Assuming you've correctly assigned a valid prefab GameObject to your 'bulletPrefab' variable, it looks like it should work. You say the "bullet still doesn't fire". Have you ensured that the AddForce method is being called i.e. add some debugging to that Fire() method to ensure it's being hit. The only other thing I can think of is that you need to be ...


0

Recognizing time is pretty expensive but you can do it just once with a System.Timers.Timer and let that drive your timers. I.e.: public class EfficientTimer () { //A static timer that drives all other timers; ticks every .1 seconds static System.Timers.Timer GlobalTimer = new System.Timers.Timer (100); //What the EfficientTimer keeps track of ...


0

public class ShootBullet : MonoBehaviour { public GameObject bulletPrefab; float attackSpeed = 2f; float cooldown; void Update () { if(Time.time >= cooldown) { if(Input.GetKeyDown (KeyCode.Space)) { Fire(); Debug.Log ("Shoot"); } } } // Fire a bullet void ...


0

You will probably have an easier time with a catmul rom spline. You give points for the path to pass through and it figures out the rest. A catmul rom spline is a type of Hermite spline, which is a different mathematical form of bezier splines. http://www.mvps.org/directx/articles/catmull/


1

Alternatively, you could use System.Timers.Timer which is probably the most performant of any solution. The following example shows a countdown for 100 seconds. System.Timers.Timer LeTimer; int BoomDown = 100; void Start () { //Initialize timer with 1 second intervals LeTimer = new System.Timers.Timer (1000); LeTimer.Elapsed += //This ...


1

Coroutines are you friend I think on this one... http://docs.unity3d.com/Manual/Coroutines.html Here is an example: void Start () { StartCoroutine ("Countdown", 10); } private IEnumerator Countdown(int time){ while(time>0){ Debug.Log(time--); yield return new WaitForSeconds(1); } Debug.Log("Countdown Complete!"); }


1

I don't fully understand your question. But, if you want to move something forward, what I would do is something like: this.transform.position += this.transform.forward * moveSpeed; Whereas, moveSpeed is the speed at which you want your unit to go forward. To go in the opposite direction that you are facing: this.transform.position -= ...


0

Use transform.TransformDirection() along with Vector3D.forward (or .up or whatever). TransformDirection() will convert the 'forward' direction of the player to that direction in global space. EDIT: oops you want to transform the direction the other way, from world space to local space, not local to world. Use InverseTransformDirection() Another simple ...


1

When an object has a Collider set to Trigger, but no rigid body, it's called a "Static Trigger Collider". This is likely the scenario for both your collectables and your cat. If you look at the "Trigger messages are sent upon collision" chart near the bottom of this page You'll see that two Static Trigger Colliders will not interact with each other. If ...


1

Because the copy of "MainMenu" you selected is not the MainMenu component in your scene. Its the one in your assets folder. Be sure to find the one in your scene. Then you will see the method.


0

On Unity 5, you may use Profiler window http://docs.unity3d.com/Manual/ProfilerWindow.html


2

I wouldn't seperate the mountain generation from the general terrain generation but combine them. Today the usual approach to generating landscapes is using 2D or 3D noise functions like perlin or simplex. By combining several amplitudes and octaves you can add both general height (like mountains and valleys) and some detail. You'll probably need to ...


1

You should convert you mouse position first using ScreenToWorldPoint before you compare it with transform position Remember that Input.mousePosition returns your cursor position on screen(Vector2), not on world point(Vector3) you might find your answer here: http://www.raywenderlich.com/61532/unity-2d-tutorial-getting-started on "Controlling Sprites" ...


0

I've faced similar issue, and after digging around I found this. Hopefully, its useful for you ref: http://answers.unity3d.com/questions/217351/animations-ignore-timescale.html


0

Unity 5 adds the PlatformEffector2D component, which I think solves this same question. If you add a collider and attach it to this effector, you should be able to create the one-way platform with less fuss, which would simplify the code for dropping down, as well.


0

You have to cast it to ClientValues type. var cSharpScript = (ClientValues)gObject2.GetComponent("Clientvalues"); or var cSharpScript = gObject2.GetComponent("Clientvalues") as ClientValues; First one causes runtime error if cast fails and the second one returns null if it fails. Important difference. But both should do the trick.


0

Be aware that a RPC function has to be unique within a scene. I wrote an blogpost explaining this in detail: http://parttimeindie.com/2015/05/08/understanding-and-using-rpcs-in-unity/ To Summarize the blogpost: A RPC Method Signature has to be Unique inside a Scene, you can not have multiple instances of one script or Two Scripts with a Method with the ...


0

if you do happen to have a static variable, just initialize it again in either Awake() or Start (); then whenever you need to restart your level just call Application.loadedLevel I was able to get it to work like this: public static int aNumber; void Awake () { int aNumberInitial = 5; aNumber = aNumberInitial; } void restartLevel () // Call this ...


2

After some more testing, it appears the problem was the Start() method. Apparently, for whatever reason, the code was being executed as follows: orbControl instantiated -> SetDirection() -> Start() Thus, because of this, direction remained 0. So, I changed Start() to Awake(), and all's well. It appears to me after more research that this is the main ...


0

There are a lot of things that you need to consider. First of all, where are you hosting your servers? UDP works great if your hosting your own hardware, but if you're using something like AWS then you'll end up spending a lot of time trying to get a good reliable solution. UDP traffic can not be load balanced using the default load balancer, so you'll have ...


0

Drop in a couple breakpoints and see if either of the MoveHandler condition blocks are actually visited in the following code : if(MoveHandler.facingRight) -> orbControl.SetDirection(BasicAttackOrb.RIGHT); else if (!MoveHandler.facingRight) -> orbControl.SetDirection(BasicAttackOrb.LEFT); Since those lines are responsible for changing the ...


3

From the documentation: RPC calls are always guaranteed to be executed in the same order as they are sent So, yes, it's guaranteed to execute A then B as your code defines it.


0

I tested your script and was able to dynamically adjust the colors of the line renderer. Perhaps you didn't pass your linerenderer component into your script in the editor on the attached object? Alternatively, you could add to your script: void Start() { lineRenderer = gameObject.GetComponent<LineRenderer>(); } Aside from that your code seems ...


1

There are some workarounds to this problem without needing to completely reinvent the wheel. For example, you should be able to load any file from any location using the TitleContainer.OpenStream method. Then, once you have the stream you can convert it into a Texture2D.FromStream method. Of course, you'll need to do your own research to figure out how to ...


1

I don't think you need XNA any more. Just double click on Content.mgcb to open the content editor. Right click on Content -> Add -> New item -> Spritefont description, give it a name, e.g. "testfont" Load your spritefont in game: var font = Content.Load<SpriteFont>("testfont"); Use it! spriteBatch.DrawString(font, "hello", new Vector2(10, 10), ...


0

this is my first time helping on a question and is hard for me to understand others when they dont use a graphic exaple. Apologies in advance. Considering that your game is turn based and your AI units can only move one tile per turn, and considering that they get stuck so easily, then I have to make some assumptions on how you game works and offer at the ...


1

I assume you assign a Prefab to public GameObject missile in the inspector. When you try to destroy missile inside of your OnTriggerEnter2D method, the error message does make sense, since you're trying to destroy a prefab and not an instance. Instead of trying to destroy missile, you should destroy the object that collided with your GameObject. So, ...


2

For arbitrary shapes The basic algorithm goes like this: // Gets the distance from a point to a shape made of line segments. float GetDistance(Shape shape, Vector2 point): min_dist = float.max; foreach LineSegment line in shape: dist = GetDistance(line, point); min_dist = min(min_dist, dist); return min_dist; // Gets the ...


0

PlayerPrefs creates on file on the disk of the device the app is used on, so it will not save between editor, and device. Other then that your code seems fine, I have noticed that if you build to your device on each test, that sometimes you lose your PlayerPrefs.


0

So, after @Jon helped me understand HLSL and render targets, I could understand more tutorials on the internet and I found my answers in the following links, if anyone is interested: First I read some of the Riemer's tutorials of HLSL to understand its basics. Second I read RB Whitaker's HLSL/Effect tutorials to get some more information. Third I read the ...


1

Make the float move variable a class variable. Then create 2 methods which the left and right UI buttons will call on Pointer Down, e.g. MoveLeft() and MoveRight(). Inside them, set move = -1 for left and move = 1 for right. If you want the character to stop if the buttons aren't pressed, you can also make a StopMoving() method on Pointer Up for both ...


0

The biggest optimization you can do is to calculate this on the graphics card -- one way to do that is to use Graphics.Blit and a shader to do the brightness/contrast effect. The result has to be a RenderTexture, but if you need the result in a Texture2D, you can use Texture2D.ReadPixels to copy the data from a RenderTexture to a Texture2D, in about 3 lines ...



Top 50 recent answers are included