Tag Info

New answers tagged

0

You can always just stuff all weapons in one big list and access them with an index. [System.Serializable] public class Weapon { public string name; public float damage; } [System.Serializable] public class Player { public Weapon[] weapons; public int currentWeapon; } public Player player;


1

As long as the player is alive, you can increase the offset of the texture. Basically the player stays still and the texture moves. Little cheating in this method as it takes around 20 lines of code and isn't fancy.


0

It's a good idea to keep your static terrain in a single buffer. Updating it for small changes is totally reasonable. However for something like an animation I think you're going to need to diversify your terrain system. Objects like doors, levers, and other objects that need to be animated should not be drawn with the same buffer as the terrain buffer. ...


0

You could make a trigger at the bottom of the ball and then check if the floor is in this trigger.


1

Do not use full screen quads for your light volumes. A simple way is to draw a sphere for each light, in the position that the light occupies and of the same radius. This way, only the fragments actually affected by the light will be affected and your fragment shader will not be executed for the entire screen surface.


1

I think Fuzzy Logic answer is best suited for your question (he got my +1), but i'd like to give a naif alternative. You can setup a bunch of Unity objects like quads, text, sprites (call all that TerminalStuff) and use a separate camera (call it terminalCamera) that capture the terminalStuff (perpendiculary). Then set the render output of terminalCamera to ...


2

You will want to use Texture2D.SetPixel or Texture2D.GetPixels and Texture2D.SetPixels if you want to blit sprites onto your texture. You could render your sprites to a RenderTexture. It may be faster but until Unity5 it was a Pro-only feature (which I don't have) so I haven't experimented with it yet. You can't draw individual pixels on the GPU without a ...


0

I'd like it to be at least vaguely human-editable I would take this to be your first requirement. Storing it in the colour data of a bitmap is probably not going to help here so I'd go with something else. For a 2D tile based game it might be worth investing some time to learn how to use an existing tile based map editor like Tiled. I'm currently ...


0

Just store it in JSON. Storing it in the colors of a bitmap seems like you're being tricky for no real reason.


2

If you can have objects linked via the inspector and public/serialized fields, you should absolutely do it. It's the best way. FindObjectWithTag is for when your objects don't live in the same scene, and they don't have scripts for registering for each other. And finally, it's useful for when you need to reference a script before Awake has run, so it may not ...


0

Actually the 2D-Vector solved the problem, I don't know why, because I think it should do the same but this is my code now and it's working Vector2 target = Camera.main.ScreenToWorldPoint (new Vector2 (Input.mousePosition.x, Input.mousePosition.y)); Vector2 myPos = new Vector2 (transform.position.x, transform.position.y); Vector2 ...


0

You have to call you coroutine by writing "StartCoroutine( wait )". You should put something before and after the yield command or else it is skipped. Try creating a boolean and disabling or enabling it before and after the yield, then you could adjust your code to check for that boolean and then run.


0

As long as you only have one spawner, it doesn't look like the spawner could be instantiating 10 platforms. However, it's definitely possible that you'll get two. On the frame after the platform is instantiated, if Spawner.Update() gets called before Platform.Update(), then spawnNewPlatform will still be true and another one will get created. Try setting ...


4

Use a logarithmic scale where drawnRadius = log(actualRadius). You then end up with a spacing like this which shows all the planets quite neatly separated: (this representation appears to be using logarithm to base 4) When you want to apply this to your planetary simulation, you first need to convert the carthesian coordinates (x, y) of each planet to ...


0

Unity let you set a collider "as trigger". You can set the isTrigger property true on the collider of the object you start to drag. Then use Collider.OnTriggerEnter(Collider) to check if the objects overlaps some other collider. When you stop to drag an object can switch to false its collider.isTrigger.


2

You have to use StartCoroutine (probably not in the Update) in order to start its execution. Otherwise it's only a method call: void Start() { StartCoroutine(wait(5)); }


0

While I personally love bunny hopping... As a starting point we should know the intended "Jump Speed" as a delta velocity. This figure represents the velocity increase (in the line with the "Jump Normal") during the instant of jumping once. Any velocity the player already has in line with the Jump Normal can be seen as a pre-existing "Jump Energy". This ...


0

First of all, i want to say that your question is very well written and it's a pleasure :), you would just need to remove what's not necessary in the code (audiosources, etc.) and it would be perfect. Cheers for that. For the answer, you could clamp your velocity when jumping, which would prevent you from reaching too high speeds when pressing the jump ...


2

Short answer: This doesn't do what you think it does. float pressure - A normalized value that describes the pressure applied to the device by a finger or other tool. The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure), although values higher than 1 may be generated depending on the calibration of the input device. ...


2

A possible problem is in your SetInStartPosition(). For setting the Y position it should be position.Y = screenBounds.Height - texture.Height... not screenBounds.Width - texture.Width...


0

Instead of disposing the contentmanager entirely; do ContentManager.Unload() This clears the contentmanager's content, freeing up resources and leaving it ready to load new content when it suits you. See: https://msdn.microsoft.com/en-us/library/microsoft.xna.framework.content.contentmanager.unload.aspx I use this method myself in a game where the player ...


0

It depends on whether or not you have put your script on a game object. (Monobehavior is for that purpose.) If you have not, create an instance of it the normal way. StudyScreen studyScreen = new StudyScreen(); then your update would be: void Update () { if (Input.GetKeyDown(KeyCode.Alpha1)) { studyScreen.StudyScreen(); } else ...


0

Try attaching a script to your platform instances. Then in that scripts Start() method use Debug.Log to log the parent platforms Transform


0

Create a public variable and make it's type the name of the class you want to access so then just assign the script with the class to your variable in hierarchy and after that you can access the variables and functions in the class. Hope that helps.


0

Source: http://www.udellgames.com/posts/ultra-useful-unity-snippet-developers-use-interfaces/ [SerializeField] private GameObject privateGameObjectName; public GameObject PublicGameObjectName { get { return privateGameObjectName; } set { //Make sure changes to privateGameObjectName ripple to privateInterfaceName too if ...


0

Basicaly, attach both scripts to the same gameobject (to make it simple) and in the MainMenu script just add the following variable StudyScreen sc; then in the Start() initialize it as follows sc = GetComponent<StudyScreen>(); at this point anywhere in your script you can reference public stuff inside StudyScreen.cs by doing sc.yourMethod(); ...


0

I eliminated the script's start function and just called the components in the update function. var bc = blueCube.GetComponent<PlayerMovementScript>(); var rc = redCube.GetComponent<PlayerMovementScript>(); if (Input.GetButton ("Switch")) { bc.enabled = !bc.enabled; rc.enabled = !rc.enabled;


0

I'm on mobile, so excuse me if I miss some syntax, but: float speed = 1000; Vector2D mousePosition = GetMousePosition(); Vector2D bulletPosition = GetBulletPosition(); Vector2D direction = (mousePosition - bulletPosition).normalized; bullet.rigidbody2D.AddForce(direction * speed); Where GetMousePosition() and GetBulletPosition() retrieve their respective ...


0

Try using raycast, from the point of your mouse. By creating a variable of type hit and it should be equal to Physics2D.Raycast(Camera.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); And then check if the variable is not equal to null, which means you hit something and then you can check the tag of the object and do what ever you want with it.


1

In the script of the random movement of the sprites check the distance by using the command Vector3.Distance(object a, object b). If the sprite is not in range than move/change direction of the movement.


0

As you said it was working fine, i found this thing different than other inside Update function: bc.enabled = !bc.isActiveAndEnabled; Is this logic should works on isActiveAndEnabled instead of enabled ?


0

You do not have to drag drop animation controller to your script instead you can add component to game object using inspector. Add an Animator component first. On your required key press you have two possibilities as i see: Enable/disable the component as per your need. If you want to run two different states you can use states based animations. Steady ...


0

{ 0.000000, NaN, 0.000000 }. NaN smell of division by zero. check AnglularAcceleration () AnglAcc = new Vector3(0f,(speed * speed) / (2f * theta.y),0f); AnglAcc.Y will be NaN when theta.y =0


1

I've found a possible solution. Set this.IsFixedTimeStep to false. What this does is syncs Update to Draw so that the game gets updated only as the screen can be drawn. That means that if the game were to lag the game physics (if done in update) would go slower, but it's probably worth it if this graphical glitch is annoying you. I found another post on ...


1

Any modern compiler will almost always convert a large Switch statement into a jump table; not into a succession of nested IF's. This may be ugly code, violating your sense of aesthetics, but is the most efficient means to parse such a structure. If you were to use a Lexer- or Parser-Generator tool such as LEX or YACC or any of their modern descendants, that ...


1

Can you set them up as a generic Dictionary<String, Object>? private readonly Dictionary<String, Object> _tileDefinitions = new Dictionary<String, Object> { {"_", nothing}, {"#", wallobj}, {"$", treasureobj} }; public Map Parse(string fileContents) { var x = 0; var y = 0; var map = new Map(); ...


2

Error message tells you exactly what is wrong. You are trying to load scene with name name. You have to change the string in the editor in OnClick handler to Game in your case.


0

You could use Texture2D.SetData to modify a section of the texture. Fill the section with array of Color. Using your example code: the array should be the dimension of (crate.width*crate.height) filled with Color.Transparent. The target rectangle is new Rectangle(0,300,crate.width, crate.height). See: https://msdn.microsoft.com/en-us/library/ff434430.aspx


0

Implement a "fake network" class that passes messages between threads, which has the same interface as the network class will have. Later you can elaborate the fake network to have random delays and packet loss. It will always be easier to debug network code with the fake class than with the real network.


1

I figured out how to fix this myself. This took me days just to find an answer to this question. I hope other people who find this question can use this answer. //My Codes I needs help on. using UnityEngine; using UnityEngine.UI; using System.Collections; using UnityEngine.EventSystems; public class Mouse_Detector_Temp : MonoBehaviour, ...


0

Well, the answer of Vinayak Garg is good but since you work with perspective this won't be perfect. This is basically paralax mapping and works great for 2D games. But here you want to have the road dissapear in the horizon probably. If your road is straight then just extent on this technique and add many pieces until it is looking good. Whenever you leave a ...


0

Many infinite runners scroll the road rather than move the player forwards on the road to make the road truly infinite. You can do this with 2 alternating game objects. public GameObject[] RoadPieces = new GameObject[2]; const float RoadLength = 100f; //length of roads const float RoadSpeed = 5f; //speed to scroll roads at void Update () { foreach ...


1

You can actually add multiple items to an array in one go. Just lock the inspector with the GO that contains the list, select the multiple gameobjects and drag & drop them into the inspector. No need to do anything special.


4

You could have 2 sufficiently long road segments. Place them one after another. When player moves from one road segment to another, remove the segment which is (now) behind the player, to the front of the current segment.


0

One way could be to make it so whenever the text box got focus (watch for the event), set the focus to a different control instead (maybe the main window). In that other control, you could watch for arrow key events and act on them by running the code that does whatever you want to do to the contents of the rich text box. To the user, things would seem ...


0

It sounds like you might want an editor script: http://docs.unity3d.com/Manual/editor-CustomEditors.html You could place a button on your object's inspector that would take the current scene selection (http://docs.unity3d.com/ScriptReference/Selection-gameObjects.html) and set the values to be the contents of your array. Doing it this way would require ...


2

I'm in a similar situation, but I'm trying to do a networked simulation more than a game; but I think that my approach may help your design process. My approach is along the line of your comment on IPC (inter-process communication). First, as background I am studying the book "Networked Graphics" by Steed and Oliveira. This provides a good background on ...


1

If you're learning about all this stuff, why not write a simple single-player Version 1, and once that's working, with your deeper knowledge, rethink the whole thing in-depth for Version 2 that will be multi-player?


10

Without knowing more about the exact game you're writing, and how you're writing it, it is very difficult to say generic solutions to your problem. However, you may want to consider this decision you're taking of leaving the networking code to the end, depending on how crucial networking is for your game. What I mean is that, if you're writing a network ...


1

Don't take deltaPosition.x value: Vector2 touchDeltaPosition = new Vector2(0, Input.GetTouch(0).deltaPosition.y);



Top 50 recent answers are included