Game Development Reference
In-Depth Information
Divergent Methods
At this point, when we are ready to start writing the script, there are a couple of
ways we could proceed. The first method would be to animate the door in Maya,
reimport, and use the trigger to play the animation nested on the door. The
second way is to create the animation within Unity and call up that animation
with the trigger. The third way is to use a collection of custom classes developed
by Bob Berkebile called iTween. We are going to look at calling up animations in
later tutorials so in this tutorial we will focus on the iTween method.
Unity has a lot of built-in classes and functions that help provide access
to core Unity game engine functionality. However, custom classes can
be authored that further expand scripting ease. iTween is one of those
expansions. Bob Berkebile has authored and released for free to the
community a collection that is so flexible and powerful, I find myself using it
on every single project.
iTween is available at http://itween.pixelplacement.com/index.php . Go
download it. The way to install it is simple. In Unity, create a folder called
Plugins. Out in your OS place iTween (really a C# script) into this folder and
you're ready to go. Alternately, this could be done all in the OS by creating
a folder called Plugins inside the Assets folder of the Unity project, placing
iTween there, and then reentering Unity.
Tips and Tricks
Although Mr. Berkebile has released iTween free for use, it is provided on a
donation-based system. If, after this topic, you find yourself using iTween a
lot, contribute—I did. It'll help encourage further development and updates.
Step 6: Create a new JavaScript called HallwayDoorsTriggerScript.
Open it in your editor.
Step 7: Start by declaring a variable for the door:
var door : GameObject;
Why?
This time we're using a public variable (var) as opposed to a hidden
private variable (private var). This is because this script is going to be
useable all over the place with pretty much any door anywhere. This
sort of flexibility will mean that we need to do a little bit more work
implementing the script, but this will work all over the place.
Step 8: Create the OnTriggerEnter functionality:
var door : GameObject;
function OnTriggerEnter (other:Collider){
iTween.RotateTo(door, Vector3(0,-120,0), 5.0);
Search WWH ::




Custom Search