Adding Animation

I want animation in the SDK. Until that happens, here's a hack to get it without SDK intergration

First, select your animation you want to add in the project. In the inspector, set it to "loop"

Now, select the character you want to add the new animation to. They should have an Animation Controller component, with IdleController as the animation controller. Single click it to locate in the project directory, and then copy it and give it a new name. I named mine, "Idle Priya". Scroll down on the character until you see a script called "IdleAnimController.cs". Single click to locate, copy it, and give it a new name. Copy this name, we'll reuse it in a second.

Open up this new script you made, it should look like this. The first line after the includes should be "Public Class idleAnimController" Replace "idleAnimController" with the new name you just gave it. The name of the class (in the script) needs to match the name of the .cs file.

Now, we want to add a function, which we can call with an "Event After Time" script, and it needs to have a bool method. This is mine, and I'll walk you through the logic.

** Script:

	 public void IsBusy(bool onOff){
	   //Debug.Log("busy is " + onOff);

the name of the function describes the action. In this case priya starts typing on the computer because she's occupied, so I typed "isBusy". In parenthases it says bool onOff. This is important, because it lets us set in the inspector when we want this animation to start playing, and when we want it to stop.

I then do an if else statement, where if the bool is checked (she is busy) I send our animation controller a signal. Here we're sending a bool signal, but you can send other types. Here's a link to the unity documentation on this subject. The name "busy" is arbitrary, but important, so copy it for now.

I also want her to make a typing sound when she's playing the typing animation, so at the beginning of the script I added a public audiosource and called it typingSound

After I set my animController to busy/not busy, I also tell typing sound to either play, or stop.

Now, save the script, and open up the copied and renamed animation controller from earlier. This is what it should look like

Now in the upper left hand corner, select the Parameters tab. Click the plus button and create a bool element.

Remember earlier in the script when we called the setBool function? Whatever you put in as a string (I wrote "busy") goes into this trigger. The names have to match exactly (spelling and capitalization) or this won't work.

Now, create a new node.

Name it a description of your new animation state, and create a connection between "idle" and this new node by right clicking and saying "make transition"

Connect the transition to your new node, and turn off "has exit time".

In the conditions section, click the plus button and add your new transiton state (in my case, busy)

Connect the "stand still" node to your new node in this same manner

Now create a connection going from your new node back to the "stand still" state, and make sure "has exit time" is checked. Only do this going back to "stand still", not back to "idle"

Now our script and our animation controller should talk to each other! Go back out to your character model, and go down to your modified idleAnim script. In my case, I added a public variable for a AudioSource. Add an audiosource to your game object, and apply your sound effect to it. Then drag your game object which this audiosource is applied to onto the field which asks for it on your modified idle anim script

Next we're going to call the whole animation function. Add an "Event After Time" script, and figure out how soon into the experience you want this animation to start, that becomes your "time" number. Drag your character object into the empty slot, and at this point your modified script should be available in the drop down list. Select it, and then select the new function you wrote.

Because its a bool, you can check it "on" for when you want the animation to start. Create a new "event after time" event, change the time to whenever you'd like the animation to stop, and make sure that the check box is unchecked. If you want to add multiple animations, you just need to do this process for every animation you add, a new fuction, a new animation node, and always link them out of both stand still and idle, and back into stand still.

Posted 1 years ago
Edited 1 years ago
Votes Newest


And... mic drop.

Posted 1 years ago
Edited 1 years ago