In this video tutorial we’ll be creating a fairly basic achievement system, having a texture scroll in whenever the player accomplishes a goal. Source files include HD video and Unity project files.
User Submitted Images
No images submitted yet
Discussion
51 Responses to “Creating an Achievement System”Leave a Comment
You must be logged in to post a comment.



hey loved the tutorial and i was wondering will there be any tutorials in the future that show us hoe to make to make a climb or cover system such as the ones in third person games like assassin’s creed or gears of war for example
and
keep up the good work for more tutorials to come
Hey Jsuperspy,
Sorry for my late reply! I’ve noted down your tutorial suggestions, though I can’t promise anything. Thanks for them regardless!
I am pretty sure you could do that pretty easily it’s basically an animation so you could use some sort of trigger to where when someone gets close to a climb able wall they push a to run the animation and then do a transform that takes them to the other side of the wall. I haven’t tested it but I think it would be pretty easy just put the puzzle peices together. 1. Animation 2. Wall detection 3. Transform over wall. I found it always helps to break down your problems first
frist!!!!
Great tutorial
Any idea when unity3d 3.5 is comming out?
thanks,
Sasbian
Any ideas of what’s including in that version?
Jeremy
Here is the most that I know. But should be quite the update.
http://blogs.unity3d.com/2011/06/16/unity-roadmap-2011/
Last I read it still says by end of the year, though Unity has mentioned it may slide into the new year. Fingers crossed!
There’s some good stuff in there.
Jeremy
Thanks for the great tutorial!
I’ve got some interesting ideas for further scripting.
Hey Mike,
Please feel free to submit any ideas you may have for future tutorials!
-Patrick
i thought about using this technique to create a menu and also organise my archievements in a list where i can see them.
Thanks Patrick.
The Unity Cookie site is really shapeing up to be for Unity what Blender Cookie is for Blender. The place to go! Keep up the good work and Thanks to all involved.
Merry Christmas,
-OldMan44
I earned the Watch Tutorial Achievement earlier. Good stuff! I wouldn’t mind seeing that quick tip on getters and setters you mentioned at some point in the tutorial. I’m a little familiar with them, but coding has mainly been a side focus for me so a tutorial on them wouldn’t hurt.
We get achievement rewards?
No. I was just joking. I was saying I watched it referencing the material from the tutorial. Would be cool if we did.
GREAT TUTORIAL! i feel a save system tutorial coming on!
Your feeling may be spot-on about that.
We don’t have a time frame for it yet though.
I would really love to understand how getters and setters work!
Thanks Patrick.
This taught me a few things that I really needed like how to get 2 scripts to talk to each other and share information.
If I wanted to set up a first person type of game and I had switches on the wall, how would I go about making them mouse clickable?
I’d like to use them for switchable doors and lights.
Some sort of MouseOver maybe?
My problem is two fold. When I move the mouse my “head” turns. Enable a cross hair or an icon for the mouse like a hand?
Hey Gary,
There are multiple ways to do what you want. For basic click functionality like a light switch you could use the OnMouseDown function (http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseDown.html). However, this can only be called from a script on that lightswitch object, which isn’t always desirable.
Also, since you mentioned you wanted to change the cursor according to what’s underneath it, I’d recommend looking into Raycasting (http://unity3d.com/support/documentation/ScriptReference/Physics.Raycast.html) in combination with ScreenToWorldPoint() (http://unity3d.com/support/documentation/ScriptReference/Camera.ScreenToWorldPoint.html).
Hope this helps a bit; good luck!
-Patrick
Thanks, Patrick. Thank you for the links too. Nice touch.
I was watching a good tutorial on VTC.com on setting up a first person shooter and he explained Raycasting.
The problem he ran into was that Raycasting shoots the beam from the center of the “player” object, so I’d have to add in a null object, and shoot it out from there. That should give me the height I’m looking for.
(We need a forum here, guys.)
I assumed I’d have to use Raycasting so the switch could not be activated from another room.
I’m thinking of using Unity as a visual walk though.
I would think I’d want to attach the script to the switch for the light. That’s where I’d expect it in real life to be.
Actually, as I’m thinking about this, the switch script should live in the light object, and the switch object could be drug and dropped from the inspector.
This way the lamps could be a prefab, expecting a switch object to be connected to them. Or perhaps multiple switch objects, as in a 2 way or 3 way switch.
(Now I can’t wait to get home tonight to test this.)
Ha, the age-old debate of where a script should live/ which class should manage what.The way I see it both are perfectly justifiable though.
Either the light switch handles it’s own toggling and passes it’s state (on/off) on to it’s associated light that’s connected in the Inspector, or the light does it, and has a switch ‘assigned’ to him, like you mentioned. It’s all a matter of perspective.
Is there any way in the future we can get before and after project files to work with? It’d be nice for noobs like me to have it set up where you begin the scripting in the tutorial and another of the final copy for people who just wanna look around at which you did.
Jeremy
I really like that idea! I’ll be sure to run it by Wes and see what we can do on this. =)
I like that idea too jcdeighan. I’ll second this Patrick.
Sweet, thanks Patrick!
Jeremy
and Gary, call me Jeremy.
I haven’t figured out how to change my login name to just my name yet…
Hi Jeremy. My profile says Usernames cannot be changed. Maybe they can do it if you email support. They are really nice people here.
Patrick,
Hartelijk bedankt. Jij bent echt een goede leerar…
But enough of my butchered Nederlands. (Mijn ouders komt uit Aalsmeer, vlak by Schiphol).
I had a problem after about 20 minutes into the tutorial, when I tried to play the game, during runtime, I kept instantiating the “Achievement Object” and wasn’t displaying any GUI texture. I am guessing this is because of the following line: “var go:GameObject = new GameObject(“Achievement Object”);”. Does the “new” instantiate? (Does that even make any sense?) I mean, does that replace the instantiate command at runtime? If so, I am wondering, if I have written my scripts exactly like you did yours, why this is happening.
Maybe I have to watch the tut over again.
Bedankt
Mike
Patrick
Disregard most of that last post (except for the dutch),
I think the problem was that I didn’t assign the First Steps texture to the Achievement Manager script.
Seems like after it compiled and I cleared all the errors, the problem went away.
On to more learning, trying to work my way through the rest of the tutorial, but it’s getting late and I’m getting sloppy.
BTW, are you taking requests for tutorials? If so, I would like to learn the basics of javascripting for unity, like teaching us the syntax, what are classes, variables, etc, and how do they all fit together, and why some are capitalized and others not, things like that.
Otherwise, I think I am learning some best practices from watching you work. Please keep up the excellent tutorials.
Mike (again)
Basic javascripting tutorials would be great! Maybe these could be a TIP tutorial like those found on blendercookie.com
Jeremy
Hey Mike,
First off, nice Dutch! I know it’s a fairly difficult language to learn, so kudos on that one!
).
As for your question: We are definitely taking requests! We can’t guarantee to do all of them, but it gives us a very clear view of what people want to learn. =) I don’t know if you’ve seen these already, but Gabriel and I both have an “introduction to scripting” tutorial up here on the site (heh, small logistic error, so you get double the fun
Here’s Gabriel’s: http://cgcookie.com/unity/2011/11/30/unity-3d-introduction-to-animation-2/
and here’s mine: http://cgcookie.com/unity/2011/12/12/introduction-to-scripting-in-unity/
If there’s anything missing from these tutorial that you’d like explained, please do let us know! We’ll definitely do more tip videos as well, as Jeremy suggested in his reply below, so feel free to comment/ request!
-Patrick
Hey there Jeremy?
http://www.w3schools.com/js/
This is a nice site for learning JavaScript. I used it back when I did a lot of web programming. It’s a nice environment and it has places to type in code and try stuff on the fly.
I was kinda hoping Patrick would make something in C# to show off what it can do.
As soon as I get my voice back, I’m planning some easy video tutorials. I promised Jonathan I’d do a demo, then got this cold or whatever it is. haven’t had a decent voice in weeks.
I’m now using C# (pronounced C sharp) along with VB.NET to build applications for work and I’m liking it.
“Never thought I’d be a C geek.” *hangs his head*
Aw nice man, I used to go to that site back in the day and forgot about it!
Jeremy
Discovered Unity, from blender; use c# and xna but like what I see in Unity so trying it out.
Nice tutorial. Only glanced at it so far but will watch in full later. Think i’ve watched almost all of ‘em now.
And yeh I’m hoping Unity Cookie follows in CG Cookie’s footsteps.
Thanks Nicholas! Glad you like it so far
Patrick! You are crazy awesome man! …keep up the awesomeness, cause…you’re AWESOME! Thanks for the tutorial!!
Thank you for the awesome tutorial. But i can’t run properly and got the following error. Any ideas what wrong and how i could solve it. thank you.
InvalidProgramException: Invalid IL code in AchievementManagerScript:unlockAchievement (UnityEngine.Texture2D): IL_0111: sub
Hi Winnie,
That’s a nasty li’l bugger; not a very descriptive error. Could you upload your code to http://pastebin.com/ and send me the link please?
-Patrick
eep! I get an error: Operator ‘-’ cannot be used with a left hand side of type ‘int’ and a right hand side of type ‘Object’.
I’m really not sure what this means.
It’s only when I have the “pixelInset.x” and “pixelInset.y” lines in there, and only when I have “Screen.width” and/or “achievementTex.width” (or .height). It doesn’t care about the edgeMargin var though, just those others.
I’ll be leaving out those two lines for now and power on with the rest of the tutorial. Good stuff!
Nevermind. I toyed with the script a bit further down the line and changed the edgeMargin to type float, which fixed it! Perhaps it’s because I’m using 3.5 and you used an earlier version during this tutorial, and that version of Unity didn’t mind? =S
Anyway, no problems now. Awesome!
Woah, did I never define edgeMargin’s type? That’s definitely a mistake on my part. I believe Unity3.5 uses strict mode for Javascript by default now, which might be the cause. I could be wrong though.
-Patrick
Truly a fantastic tutorial. Really enjoyed it and learned so much. Don’t ever remove the mistakes made during recording as we all learn tons from watching the problem resolution process as much as anything.
Cool tutorial, is there any way of making the achievements buttons?
Hey Tom,
The buttons I used were just simple graphics I made in Photoshop I believe. If you’re looking for art-related tutorials, please check out http://www.conceptcookie.com. =)
Cheers,
Patrick
Hello,i’m using fps controller for my game,so what script is my movement script?
I’ve got an error that I can’t get rid of please help.
BCE0051: Operator ‘-’ cannot be used with a left hand side of type ‘int’ and a right hand side of type ‘Object’.
guitex.pixelInset.x = Screen.width – achievementTex.width – edgeMargin;
Please can you help me with this error
BCE0051: Operator ‘-’ cannot be used with a left hand side of type ‘int’ and a right hand side of type ‘Object’.
guitex.pixelInset.x = Screen.width – achievementTex.width – edgeMargin;
hey there you need to make edgemargin a float var edgeMargin: float; that fixed it for me.
I keep getting errors, over and over again :/
Thanks for the great tutorial ^_^ just finished it (took me longer than expected since i made some changes here and there and wrote from the start all in C#)