Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Controlling scripts with animation events

From: Game Character Creation in Maya

Video: Controlling scripts with animation events

In last video, we talked about how to make local copies of animations for editing inside Unity. In this video, we'll look at setting up animation events, which allow animations to access the power of scripts by calling script functions as they play. So let's use this run-read/write animation that we created in the last video. I'll go ahead and apply that to the Third Person Controller script which is attached to our game character. So in the hierarchy, I'll just click on a game character. And down here in this Third Person Controller script, instead of the read-only run animation, I want to use this run-RW animation.

Controlling scripts with animation events

In last video, we talked about how to make local copies of animations for editing inside Unity. In this video, we'll look at setting up animation events, which allow animations to access the power of scripts by calling script functions as they play. So let's use this run-read/write animation that we created in the last video. I'll go ahead and apply that to the Third Person Controller script which is attached to our game character. So in the hierarchy, I'll just click on a game character. And down here in this Third Person Controller script, instead of the read-only run animation, I want to use this run-RW animation.

So I'll just click and drag, just drop that right on the Third Person Controller script. So now let's set up a script that this run-RW animation can talk to you as it plays. So in my Project panel, I'll click on Create > JavaScript. And we'll just title this HelloWorld. And I'll also go ahead and just create a folder for all my scripts.

And I'll just click and drag to place that in Scripts. So right now this is just a blank script, so I'll double-click and we can make some edits here. So right now, we have a default function called the Update function. So that's a function that automatically comes up in any script and there we could place scripting language to control things that happen every frame. In this case though, we're just going to make a very simple function. So I'm just going to type function and I'll title it Running.

And all our function is going to do is output some text to the console. So the command to do that is Debug.Log and then we can just type in our message. So I'm just going to have him say "I'm running." So this is about as simple as you can possibly get with a function. If you don't have much experience with JavaScripting for Unity, again I would take a look at some of the documentation. There are some really great tutorials for scripting.

And it's actually a lot of fun. You can do some really powerful things with scripts though Unity. So let's go ahead and save this. And we can quit out of our text editor. Whoops! I'm getting an error down here already. So let me just double-click one more time. I forgot my semicolon here. Okay. So I want to take the script, left-click, drag over to the hierarchy, and just apply it to our game character. So now let's click on root again and go in and add an animation event to our read/write animation.

So I'll bring up the animation window by clicking Window > Animation and we'll edit our run-RW animation. So in the timeline here, right below there's this little track and that holds animation events. So I can drag the time slider out. Let's say halfway through I want to add an animation event here and I can just click Add Event, so I've got an event here. And right now, there's no function selected. So basically an animation event is just going to talk to any of the scripts that are attached to the game object that you're animating.

So to edit this, I can just double-click and it's going to ask me to pick a function. So right now I get a big list. So these are all the functions from all the scripts that are attached to my game character right now. What I want to pick is this Running function. So as this animation plays, when it hits this point, it's going to call that Running function that we just set up in our script and it's going to print that text to the console. Okay, so I'll close out of the animation window.

And I'll go to Window. It'll bring up the console so we can actually see the text that we're going to get when we play. And I'll just click this tab here, just drag it right down to the Project window. So one thing about the Unity interface is it's really easy to customize, so you can reposition and drag around windows as you need to. So I'll go ahead and switch to my Game view. Let's go ahead and play. So I'm going to hold down Shift+W and I should see in the console now my text is appearing as that running animation plays over and over again.

So that's a really simple example of how to get an animation to talk to a script. Now obviously, you would probably want to do something more elaborate with your script. You could use it to control other game objects that are in your scene, maybe turn a light on or off, something like that. Really, the sky is the limit and it's just a matter of getting familiar with scripting and getting familiar with Unity.

Show transcript

This video is part of

Image for Game Character Creation in Maya
Game Character Creation in Maya

40 video lessons · 8970 viewers

Chris Reilly
Author

 
Expand all | Collapse all
  1. 3m 50s
    1. Welcome
      39s
    2. What you need to know before watching this course
      1m 9s
    3. Understanding game asset creation
      1m 21s
    4. Using the exercise files
      41s
  2. 25m 35s
    1. Setting up scene folders (Maya and Unity)
      3m 58s
    2. Optimizing geometry
      3m 14s
    3. Using symmetry
      4m 8s
    4. Extruding geometry
      4m 19s
    5. Sculpting geometry
      4m 1s
    6. Importing reference sketches
      5m 55s
  3. 37m 14s
    1. Modeling the head and nose
      5m 34s
    2. Creating the mouth
      4m 28s
    3. Crafting the eyes
      5m 11s
    4. Building the body and a wing
      10m 11s
    5. Forming the limbs
      8m 5s
    6. Adding finishing touches
      3m 45s
  4. 36m 11s
    1. UV mapping overview
      2m 43s
    2. UV mapping the body parts
      9m 18s
    3. UV mapping the face
      7m 40s
    4. UV mapping wrap-up
      3m 44s
    5. Mirroring
      4m 57s
    6. Texturing
      2m 46s
    7. Normal mapping
      5m 3s
  5. 46m 21s
    1. Setting up the skeleton
      5m 19s
    2. Building the spine
      3m 39s
    3. Finishing the skeleton
      4m 32s
    4. Rigging the legs and feet
      8m 35s
    5. Rigging the torso
      3m 49s
    6. Rigging the arms and hands
      3m 35s
    7. Rigging the face and head
      5m 9s
    8. Rigging wrap-up
      2m 27s
    9. Skin binding and weight painting
      5m 26s
    10. Animating in Maya
      3m 50s
  6. 29m 9s
    1. Exploring the Unity interface
      3m 3s
    2. Importing character and animations into Unity
      5m 50s
    3. Controlling animations with scripts: Third-person character controller
      7m 14s
    4. Controlling animations with scripts: Third-person camera controller
      4m 4s
    5. Making read/write animations using UnityScript Editor
      4m 8s
    6. Controlling scripts with animation events
      4m 50s
  7. 19s
    1. Additional resources
      19s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Game Character Creation in Maya.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.