New answers tagged

-1

This is so simple, Just checked that loop object have your specified componentes or not if it is not null then add in the list. foreach(var go in list) { if(go.GeComponent<Component1>() != null) { compList.GeComponent<Component1>(); } }


0

LINQ is probably the best way to go, but switch your Select and Where so you don't have to call GetComponent twice var components1 = list.Select(r => r.GetComponent<Component1>()).Where(g => g!= null).ToList();


-1

By definition, all variables SHOULD be private. Every function or variable is private by default in Unity, but there's no problem writing the 'private' reserved word. If you want to get or set one of them from another class, you have to create a getter/setter function, but these functions must be public, otherwise they will be useless. There is no problem ...


0

While there is no way to answer your question in terms of cost with the information you've given, you may be interested in looking at Unity's Unity Multiplayer which is free for up to 20 concurrent players. Also available is Amazon Lumberyard, which integrates with Amazons GameLift, which also has a free tier. The price will increase as the number of ...


0

It's called collision detection. 8-bit computers did this using player-missile graphics in hardware. Modern day game engines use physics engines and linear algebra. The current direction of a weapon is represented as a 3D vector. That provides an infinite line in the direction of fire. Every moving object has one or more bounding sphere as that's the ...


1

I'm far from an expert but I've been working on a multiplayer 2D shooter game in my spare time. My method There are varying bullet classes between the client and server (even when playing offline, a server instance is started on a separate process and connected to by the 'main' game). Every tick (60 per second) the client works out a bearing between the ...


6

Wouldn't it be hard on the processor to process thousands of these objects being instantiated, then destroyed (when on-hit effect is triggered)? RAM space? I think you're underestimating just how fast computers are. This was sometimes a problem on the systems of the 80s and 90s. It's partly why the original Space Invaders won't let you fire another bullet ...


42

Probably one of the most efficient ways to implement bullets is using what is known as hitscan. It is rather simple in its implementation - when you fire, you check to see what the gun is aiming at (possibly using a ray to find the closest entity/object/mesh), and then you 'hit' it, doing damage. If you want to make it seem more like an actual, fast moving ...


7

I'm by no means an expert, but to answer your question, yes, you would need many of those things you mention. For your 2D example, you could have a position and velocity for a bullet. (You might also need a lifetime or maximum distance, depending on how you implement your bullets.) That would usually involve 2 (x,y) values. If they were floats, that's 16 ...


75

I can certainly see why you would think that it would be hard to simulate those, but there are enough constraints on bullets (all projectiles, really) to make them easier. They are generally simulated as a single point, instead of as something with volume. This makes collision detection significantly easier, as now I only need to do collisions against ...


0

The way I would handle this sort of scenario is to use some form of event messaging system. Each entity in your game world(and possibly the game world itself) should have the ability to send and receive messages. A simple way to set this up would be to have a MessageTypeEnum that signals which type of message is being sent and then some way of sending the ...


2

Why not use colliders and tags. When an enemy trigger/collider detects a player trigger/collider tagged say "Player kick" (child game object of the player) then that enemy executes his reaction with OnTriggerEnter(2D)/OnCollisionEnter(2D). Player just needs to enable and then disable its kick game object when kick is pressed. The most important thing is ...


0

Your stack error comes from the fact that 'AdView' is a type, not an instance. For example, let's say you have the following class: package simulator; import java.awt.Color; public class Dog { public Color coatColor; public static boolean mans_best_friend; } because all dogs are man's best friend, the statement Dog.mans_best_friend = true; is a ...


0

There's a couple of ways you could go about such a system, as with anything. I'll try to describe the core of one such system in a pretty general sense here: An animation consists of AnimationFrames. An animation frame contains a bunch of data. struct AnimationFrame { //The graphic for this frame Sprite * sprite; //Duration (for example, ...



Top 50 recent answers are included