This week's topic should be useful in my opinion although I have experience in debugging. Anyway in case of scripts and Unity things should be different a bit. Let's start from the lecture as always!
How to find bugs?: In my opinion and experience a debuggin on paper is maybe the most effective way although it consumes more time that e.g. debugging using a debugger because you have to e.g. update the variables on the paper each time manually and the debugger does it in your place. But nice thing about paper debugging is that you are acting as an interpretator so you feel some kind of total control on your program which is cool:) Also for me many logic problem are solved much more easily with this method.
I used debuggers quite many times but an embarassing thing is that I always was lazy to study info about some features, e.g. breakpoints! I knew only those that are intuitively clear how to use. But now at last I will learn a bit more I hope. Instead of breakpoints I always used run to the cursor but now I see it's quite manual way of debugging and it might be more convenient to set breakpoints in needed places rather that switch through sources and click a mouse each time.
What are tracepoints?: Well maybe useful thing sometimes instead of incode tracing but that has some disadvantages. For example unlike incode tracing( and debugging in general) I don't thing that tracepoints and traces can be so easily ported to another debugging tool if nessasary or goven to another programmer. So currently I preffer incode tracing. But it would be nice if IDE's would generate trace code automatically and there would be an option t hide debugging code when needed.(I have never used or met such features).
It would be good to hear how debugers work actually. Maybe it is not that easy but I think we have to know at lease the basic principle.
From the lecture I didn't get what is the difference between soft and hard debugging and GDB, what are their pros and cons. Seems I should look into the Web for that. It also was a bit frustrating for me that it wasn't explained why we should use soft debugger and mono develop in most cases. I always like to understand what things I am doing and why.
Ok from the lecture I got a couple of new things such as breakpoint. Sadly tracepoint were not demonstrated at all:(. Not that advanced level I expected. Also I in the video tutorial of debugging and in my experience I see that it's more than frequently needed to step BACK. The fact that I haven't met this shows that this feature is hard to be done. But it would be really needed feature.
I will skip debugging excersises for now as I find them quite boring and not useful for me and will go to "candy" - developing the game futher.
Lets start things!
First of all I will do the remained task from previous week on joining wheels and box.
Ok, seems like a hinge joint is appropriate solution. Joints are useful but... it is a physical cheat to be honest. I wonder, is it possible to create a real joint which consist of physical objects completely. Then it will better simulate the real world I suppose. But proably perfomance will be decreased.
It's not that easy I see to get things work. I had to put 4 wheels but they are behaving like non-physical objects: they are ingoring collision with platforms! I don't know what is wrong. I have to look at reference answers for assistance...
Hm... Joints are not used there! Interesting... Aha! There are box and wheel colliders attached but they are not rigid bodies - that's the solution. Ok..
Now I will start the 2nd task.
I used our previous version of the project (the result of working on 2nd module) as a base. I noticed that it is quite hard to pull the cart on the moving platform because of it's small size and because it doen't stop at the bottom. So I resized the platform but I didn't touch the moving behaviour because it's even more interesting I think in this way. But the cart being placed on the platform behaves like it is too light, it is loosing it's balance and rotating. I tweaked many params of the cart but it is still bouncing.
Ok after some tweaking I get desired results. Now I have to "Make it possible to load the ship fuel."
I found a ShipFuelTrigger already done from solution of second week but I will do my own script.
I found an interesting thing in Unity: actually there're classes for Colliders, GameObjects! And I though it is hidden in Unity engine and we can only manage these objects though Unity IDE!
I studied GUI basics of Unity from the manual. Things are strange for me. I used GUI systems in Software in other way, there aren't OnGui stuff and GUI.smth to create smth. I don't understand why e.g. we have to redraw the button each time with OnGui, event based system I think is more elegant. But I see there's no way but only one in Unity(at least in non-Pro version:)).
Ok after some time I the button "Load Fuel" is desplayed each time the fuel is near the ship and the fuel destroyed when the button is pressed . Here is an interesting issue: where to put trigger script in the spaceship ot in the fuel?? I decided to put in the fuel for Fuel should know how to destroy itself and explose.
Now I need to make an explosion animation when the fuel is loaded into the spaceship.
After about an hour I did my very own(except textures) explosion using particle systems. Now I should make it instaniated when fuel is loaded.
I decided to make the game fair, i.e. the player won't be able to enter the ship if the fuel is not loaded. So I have to make a fuel_loaded member variable for the Ship. And that may be a bit challenging for I don't have Spaceship class but a set of scripts attached to Spaceship game object. For simplity I will add the entering script to the spaceship not to the Lerpz so I can easily access fuel_loaded.
I noticed that altough MonoBehaviour has OnTriggerEnter method, when I begin to type this in the script, the IDE don't suggest to fill the name of the method to the end, which is a bit frustrating.
I found another disadvantage of not creating separate class for each new GameObject(Ship, Lerpz) - when we want to call some method of other game objects we have to use this nasty CallMethod method which is not a good solution.
Some difficulty I met when I was finding out how to detected that the collider in OnTriggerEnter is Lerpz. When I checked that colloder==lerpz it doesn't work because actually the footEffects is the trigger of Lerpz. I am sure that there should be more convenent way than passing footEffects as a parameter to the script but I don't know which way.
foorEffect turned out to works badly so I added separate tigger area to lerpz.
I have a problem hiding/destroying lerpz. When I set active=false the lerpz remains. But GameObject.destroy works! But there's a hidden problem: it will destroy the lerpz not hide it so it's at first chating because the lerpz actually should be inside the spaceship, and at second all the members variables of lerpz will be missed, e.g. it's coins, experience or whatever. But for this time I will do in this stupid way of destroyin the lerpz.
Wohoo! I did it: the lerpz now can enter the ship when the fuel is loaded and I can control the ship but there's a problem with camera: it remains at the same point and not follows the spaceship.
I found a method in CameraScrolling script of main camera but to coall it with CallMethod I have to pass 2 parameters which is not possible it seems. That's another problems with separate scripts. So it seems I have to use default value in that function. But no! There's an overloaded method with one param there so np. OH! CallMethod doen't support overloaded methods! No way but to put there a renamed method.
Fine I did that! Now the last thing remains..
I haven't finished the task today and missed the deadline but I think it is no problem if I sent it to the teacher tomorrow because of holiadays. So no rush..
Wow I'm spending a significant but enjoyable amount of the time on this course, especially on this task!
I used a rotating particle system as an appearance of teleport: looks flne! But I don't know what effect to use when the ship has dissapeared. After a while I decided that the teleport will get smaller and smaller and then a blue explosion will be shown.
Hm, strange! When I copy-paste the explosion from fuel and change it's appearance that of fuel is changed also in the same way! Crazy!
At last! I found an issue: particles! I used in both cases flam particle and when I channged the color in particle system I actually changed the flame itself!
Yep, fine! Now "Quit application after ship has disappeared and final effect has been shown." I think it's not difficult:)
But not that easy because there aren't event's in Unity!!(it seems) So I ended up with this:
if(final_explosion_instance==null&&explosion_beginned) //the game ends after final exposion is gone
which is not beatiful
As for me there may be much better script support in Unity.
Fine I tested the game and all works!
I am attaching some screens demonstrating what I finally did in the task. Enjoy!
Totally I spent about 1080 minutes on this week, that's about 18 hours(if I didn't confuse my calculations)! I can't say of course that I was fully concetrated on the task at all times, so real time may be less.
For that time, I got a good portion of knowledge and experience about Unity and scripting. I began to understand how the whole consept of this game engine. Some things about scripting possibilities in Unity make me a bit disappointed, such as some OOP issues and invconvinces, SendMessage, no Event/callback support. But probably I simply didn't find out how to do all I wnat in Unity in the way I want. Anyway I find Unity quite a powerful and easy to study.
One important things about Unity classes structre I get is that properties of game object in Unity is not done by inheritance but with aggregation. E.g. if we make a gameobject a rigidbody then the relevant GameObject fiels called rigidBody gets "filled" with RigidBody instance. I can't say for sure at this moment that inheritance would be better solution but I think that personally for me it would be more intuitive.