Hello, i am very new in programming, so from a lot of things, i am very confused of course, but most of them i am able to sort out by google out, but here I really don’t know. - C#
So, i somehow make my first game ever, try Build a game and when i did it, the game just start acting little bit weird. I just asking, if it’s coz i wrote it in so bad way/chaotic/newbie way, or what…
I maked Tower Defense, in this moment its only spawner, which spawning infity of waves of enemies and a lot of places, where i can build my towers. When enemy is spawned, it find the way, where to go (empty gameobjects), by find GameObjects and add them in array.
The problem is, in editor work everything absolutely okey, no errors nothing.
When i build the game, the enemies go instead of over 12waypoints over 2 and taking players life straight away.
Can just somebody tell me the logic of it, i mean, why it work in editor and out doesnt?
What keyword to looking for on google to learn this thing? Its some type of Architecture or something?
Thanks for help and sorry for my bad english, i just start do programming like month ago and this make me little bit sad.
You need to be more specific about the behavior. Show some screenshots of what it should be doing, and what it’s doing in a build.
Some of the most common things, though:
You’re doing things over time, but you’re not using Time.deltaTime, so you get different behavior depending on framerate. This affects things that have a “speed”, where those things will seem to go faster or slower in a build, or on different hardware.
Your UI is all messed up because you’ve configured it for one resolution, and it doesn’t work in a different resolution.
Anyway, show some screenshots, explain the issue, show the code that’s not working.
Thank you so much for answer, here is more info, hope will help, coz i really wanna sort this out.
On the picture bellow, u can see my border. Enemies should spawn at beggining (left top) and they should go through all of this and on end, they should destroy them selves. But they destroy themself straight on second waypoint and they even not going straght. Here i posting even Enemy.cs script, because thats the place when enemy looking for path. Hope u will see there something else then mess and unexperience.
You should not assume that the objects will be in a specific order. You’re probably getting them in reverse order in your build. I’d try to define your waypoints as an ordered array, not by finding the waypoints in the scene.
Okey, so from what did u say, i guess easiest way what to do, when i arrive home, is just manualy put it in array and after that fallow the waypoints, right?
U have any idea how to do it properly? i mean only whats on my mind is for loop.
Thank you so much.
An easy way would be to put the waypoints in a public array property on some class in your scene, and assign the waypoints in the inspector. Something like this:
That class just has a public Transform[ ] Waypoints; property, and I assign the waypoints in the correct order in the inspector. This is fine when there aren’t too many waypoints.
Another approach is to put a component on each waypoint that defines its sort order, just an int value that defines the relative order of waypoints. Then, you can still use FindObjectsOfType, but then you’d order them by that value.
Yeah, the first way i ment. Thank you so much, it’s acting much better already.
So basically i need to make sure, unity exactly know, where is the point.
It’s need to be prefab? I don’t think so, no?
I don’t really understand your last question. But, the way I handle this kind of thing is to have each level store the waypoints, and then I assign those waypoints to any enemies that spawn in that level. So, one SceneController stores the waypoints, and that controller assigns them to the enemies that spawn.
Note that these types of issues are why you should do the majority of testing on builds instead of the editor. Use play mode in the editor to look at changes as you go, do actual testing in a build. My opinion of course, but it avoids these kinds of issues.