Help with dynamically created objects.

I wonder how do I get to create a dynamic object and set it as a child of an object not created dynamically, that the object follow the same way as is done in the game Snake Game. anyone know some way or some function that I can use to solve this problem??

Although I haven’t tried to implement a snake game in Unity myself, I don’t think entity parent-child relationships are what you want for the segments of the snake’s body.

Consider that a segment of the snake’s body is not ‘locked’ to the segment in front of it, but rather replicates it’s motion after a brief delay. A parent-child transform relationship implies ‘locking’, more or less, so I don’t know that it’s an appropriate solution here. (You could certainly tweak the behavior of a child entity so that it appeared to follow the parent entity, but IMO, it would be more trouble than it’s worth.)

So, rather than using parent-child relationships for this, I’d recommend using some other method instead. (A logical choice would be to represent the world using a grid, and have each grid cell store information about which direction to move in next.)

hmm thank you for your help, but I’m very beginner at this game in the history of unity, could you informing you finish me how can I make this grid, there would be a matrix each square matrix I fill with what? would use a box or an image and play hide and show depending on what the guy hit the snake move. if you can give me that little help I appreciate it.

Assuming a fairly simple snake game, you would simply create a regular grid representing the entire play area. Each grid cell can be empty, a wall, an edible item (or whatever), or part of the snake’s body. If it’s part of the snake’s body, you’ll also need to specify what direction that part of the body is moving in. (The details of how to represent the grid will depend on the programming language, but will most likely involve a 2-d array of some sort.)

Each snake body part can be a separate game object. In the update function for each of these objects, you’ll want to check the grid cell that that body section is in to see which direction it should move, and then move it to the next cell in that direction.

There will be various other details you’ll have to figure out related to spawning new body sections, dealing with growth and running into walls and so on, but those are just basic logical problems that you should be able to figure out with a little work.

If you’re having trouble getting started, I’d just dive in and start coding, and then return with any specific questions that you run into as you proceed.

I have no problem with coding, I have trouble putting this encode in Unity, the programming of the snake I have whole and in many ways my problem is to put this snake in Unity, as that I make to put the matrix in Unity and current izar the matrix d it again, that’s the only thing I do not know that part of logic programming and I turn around.

I didn’t quite follow all of that, but in any case, programming in Unity is very much like programming in any other environment; you have a few languages that are supported, and you have an API through which you can interact with the engine.

If I’m not mistaken, Unity supports scripting in three languages: C#, (Unity) javascript, and Boo. If you know one of these languages, you’re set as far as that goes. If you don’t know any of these languages but know how to program in some other language, learning a new language shouldn’t pose much of a problem. (If you need further help with this though, maybe you could tell us what languages you’re proficient in.)

As for the API, that’s just like learning any other API (e.g. WinAPI, OpenGL, Direct3D, etc.). Fortunately, the Unity API is very well documented, so it’s usually pretty easy to find what you’re looking for. (The only real ‘gotcha’ is that most of the examples are in javascript only.)

If you can program a snake game in another language and using another API, then you should be able to program a snake game in one of the languages supported by Unity, using Unity’s API.

Granted, since Unity is a complete environment for game authoring and makes use of design elements (e.g. a component-based entity system) that may be unfamiliar to some, you may have to adjust a little. But, it shouldn’t be any harder than learning any other new language or development environment.

Anyway, that’s probably as specific as I can be without further information. If you need further help, perhaps you could tell us what language(s) and API(s) you’re familiar with, and what particular problems are hanging you up.

I program web in asp.net c #, I am familiar with the markup language “c #” just can not understand how I’m going to put a matrix where GameObjects inteface on unix, you do not have any material that I can use as reference . any 2d game that uses matrix server, I just want to understand what the programming logic game, how it works etc… that has nothing to do with web programming.

What do you mean by ‘interface on Unix’? And what do you mean by ‘matrix server’?

Unfortunately, I don’t know of any references off the top of my head that show how one can make a snake game in Unity. However, with all of the tutorials that are available and all of the projects that have been showcased on the forums here, I imagine it’s been covered before. You might try searching the forums for ‘snake game’ and see what you come up with.

In any case, the easiest solution for the game map itself would probably be to make the array a global variable (public static class member variable in C#) so that it’s accessible from any script. This isn’t necessarily the best approach software-design-wise, but it’s probably the most straightforward solution.