{"id":85268,"date":"2019-09-27T14:41:25","date_gmt":"2019-09-27T14:41:25","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=85268"},"modified":"2021-07-29T19:44:06","modified_gmt":"2021-07-29T19:44:06","slug":"using-the-itween-plugin-for-unity","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/development\/dotnet-development\/using-the-itween-plugin-for-unity\/","title":{"rendered":"Using the iTween Plugin for Unity"},"content":{"rendered":"<p>It&#8217;s happened to every developer at some point; you&#8217;re trying to accomplish a simple task but the method to accomplish said task requires more lines of code than you would like. Surely it doesn&#8217;t have to be this way. This is often especially true in the world of game development, where there are often many steps required to accomplish one large goal. For example, suppose you wish to fade an object while your game is running. Two common ways to do this would be to tie the fade action to an animation and call this animation in code or interpolate some color values in your script to create the fade effect. While they get the job done, both methods require several steps to accomplish. What if there was something out there that could do all that work in a single line of code?<\/p>\n<p>You might think this is wishful thinking, but the reality is that such a feat is very possible. A plugin for Unity, iTween, can give you the result you want with minimal effort required on your end. iTween is an animation plugin that uses interpolation systems to create animations that look and feel good. The goal of the plugin, according to <a href=\"http:\/\/www.pixelplacement.com\/itween\/index.php\">its website<\/a>, is to streamline the production of your Unity project and put you in the mindset of an action-movie director instead of a coder. Here you&#8217;ll be shown a small project demonstrating iTween&#8217;s simple use and what it can bring to your Unity project.<\/p>\n<h2>Setup<\/h2>\n<p>Of course, to use iTween, you&#8217;ll have to create a project (Figure 1) and import the iTween plugin into said project.<\/p>\n<p class=\"caption\"><img loading=\"lazy\" decoding=\"async\" width=\"1002\" height=\"135\" class=\"wp-image-85269\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/09\/word-image.jpeg\" \/><\/p>\n<p class=\"caption\">Figure 1: Creating a new project<\/p>\n<p>Name the project <em>iTween Demo<\/em>. To better show off iTween&#8217;s use, it is recommended that the project be in 3D. Decide on a location for the project, then create it as shown in Figure 2.<\/p>\n<p class=\"caption\"><img loading=\"lazy\" decoding=\"async\" width=\"1002\" height=\"582\" class=\"wp-image-85270\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/09\/word-image-1.jpeg\" \/><\/p>\n<p class=\"caption\">Figure 2: Project name, template, and creation.<\/p>\n<p>First, you&#8217;ll have to get the iTween asset into your project. The easiest way to do this would be through Unity&#8217;s Asset Store. In the top menu, navigate to Window-&gt;Asset Store as shown in Figure 3.<\/p>\n<p class=\"caption\"><img loading=\"lazy\" decoding=\"async\" width=\"449\" height=\"211\" class=\"wp-image-85271\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/09\/word-image-2.jpeg\" \/><\/p>\n<p class=\"caption\">Figure 3: Opening the Unity Asset Store<\/p>\n<p>Once the Asset Store has loaded, you will need to search for <em>iTween. <\/em>The item you&#8217;ll be looking for will have a matching name created by <em>PixelPlacement <\/em>and should be free. After selecting the asset, click the download button. Once the asset has finished downloading, you&#8217;ll be able to press the button again to import iTween into the project. Once the plugin is extracted you&#8217;ll be able to import it into the project, as shown in Figure 4.<\/p>\n<p class=\"caption\"><img loading=\"lazy\" decoding=\"async\" width=\"350\" height=\"381\" class=\"wp-image-85272\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/09\/word-image-3.jpeg\" \/><\/p>\n<p class=\"caption\">Figure 4: Importing iTween<\/p>\n<p>After the package manager is finished loading, click <em>Import <\/em>near the bottom of the window to put iTween into your project. The example project will also need some music and a single sound to test out iTween functionality. If you need some recommendations, <a href=\"https:\/\/assetstore.unity.com\/packages\/audio\/music\/loop-music-free-111896\">Loop &amp; Music Free<\/a> by Marching Dream and <a href=\"https:\/\/assetstore.unity.com\/packages\/audio\/sound-fx\/sound-fx-retro-pack-121743\"><em>Sound FX \u2013 Retro Pack<\/em><\/a> by Zero Rare will have what you need for sound effects. With all your assets in place, close out the <em>Asset Store <\/em>and begin setting up the project. The Assets window should look similar to Figure 5.<\/p>\n<p class=\"caption\"><img loading=\"lazy\" decoding=\"async\" width=\"224\" height=\"100\" class=\"wp-image-85273\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/09\/word-image-4.jpeg\" \/><\/p>\n<p class=\"caption\">Figure 5: The current <em>Assets <\/em>window<\/p>\n<p>To begin, two objects will need to be placed within the game world. The first will be a regular cube that will showcase the iTween animations. Your cube object can be created by going to the <em>Hierarchy <\/em>and selecting <em>Create-&gt;3D Object-&gt;Cube,<\/em> as shown in Figure 6.<\/p>\n<p class=\"caption\"><img loading=\"lazy\" decoding=\"async\" width=\"388\" height=\"381\" class=\"wp-image-85274\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/09\/word-image-5.jpeg\" \/><\/p>\n<p class=\"caption\">Figure 6: Creating a cube.<\/p>\n<p>In its <em>Transform <\/em>component in the <em>Inspector <\/em>window, set the rotation to <em>x <\/em>-10, <em>y <\/em>45, and <em>z <\/em>-30. After that, set the scale to 2 across all axes. Figure 7 shows how that should look.<\/p>\n<p class=\"caption\"><img loading=\"lazy\" decoding=\"async\" width=\"606\" height=\"156\" class=\"wp-image-85275\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/09\/word-image-6.jpeg\" \/><\/p>\n<p class=\"caption\">Figure 7: Setting the rotation and scale of the cube.<\/p>\n<p>Create another 3D object, this time a sphere. This object will give the <em>Cube <\/em>object something to look at in a specific iTween animation. Supposing the sphere was the moon, it can be placed in the sky. The exact coordinates are <em>x <\/em>-6, <em>y <\/em>11, <em>z <\/em>15. The scale and rotation remain the same. When complete, the scene should look similar to Figure 8.<\/p>\n<p class=\"caption\"><img loading=\"lazy\" decoding=\"async\" width=\"874\" height=\"379\" class=\"wp-image-85276\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/09\/word-image-7.jpeg\" \/><\/p>\n<p class=\"caption\">Figure 8: How the project currently looks<\/p>\n<p>One last task remains before the coding part begins. Among other things, the <em>Cube <\/em>object will be able to fade in and out as though it used a cloaking device. However, its default material will not allow the fading. Instead, a new material will be created. In the <em>Assets <\/em>window right-click, then choose <em>Create-&gt;Material <\/em>as shown in Figure 9 and name the material <em>FadeMat<\/em>.<\/p>\n<p class=\"caption\"><img loading=\"lazy\" decoding=\"async\" width=\"605\" height=\"344\" class=\"wp-image-85277\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/09\/word-image-8.jpeg\" \/><\/p>\n<p class=\"caption\">Figure 9: Creating a new material<\/p>\n<p>Immediately after creating the material, navigate to the <em>Inspector <\/em>window and set its rendering mode to <em>Transparent<\/em> like Figure 10.<\/p>\n<p class=\"caption\"><img loading=\"lazy\" decoding=\"async\" width=\"605\" height=\"144\" class=\"wp-image-85278\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/09\/word-image-9.jpeg\" \/><\/p>\n<p class=\"caption\">Figure 10: Setting the material&#8217;s rendering mode<\/p>\n<p>Finally, the new material will need to be assigned to <em>Cube<\/em>. Select the <em>Cube <\/em>object, go to the <em>Mesh Renderer <\/em>component in the <em>Inspector <\/em>window, and click the arrow next to <em>Materials<\/em>. Then click and drag the <em>FadeMat <\/em>material from the <em>Assets <\/em>window into the <em>Element 0 <\/em>field under <em>Materials<\/em>. Figure 11 shows you how to do this.<\/p>\n<p class=\"caption\"><img loading=\"lazy\" decoding=\"async\" width=\"840\" height=\"490\" class=\"wp-image-85279\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/09\/word-image-10.jpeg\" \/><\/p>\n<p class=\"caption\">Figure 11: Setting <em>Cube&#8217;s <\/em>material<\/p>\n<p>All that&#8217;s left is a sound manager for the sound effect that will be played later. Create a new object, this time an <em>Audio Source <\/em>object. It can be created via <em>Create-&gt;Audio-&gt;Audio Source<\/em>. Name it <em>SoundManager,<\/em> and then the setup will be complete. To begin coding the project, create a new asset in the <em>Assets <\/em>window, this time a script, and call it <em>Actions<\/em>. Once created, double click the script to open it in Visual Studio.<\/p>\n<h2>The Code<\/h2>\n<p>To start, you want to make this script require the object it&#8217;s attached to have an <code>AudioSource<\/code> component. Doing this requires the following line of code above the class declaration:<\/p>\n<pre class=\"lang:c# theme:vs2012\">[RequireComponent(typeof(AudioSource))]<\/pre>\n<p>Once the <em>Actions <\/em>script is attached to the object, it will automatically add this <code>AudioSource<\/code> component for you. In addition, it will prevent the removal of this component so long as the <em>Actions <\/em>script component is also attached. Next, the <code>Start<\/code> and <code>Update<\/code> functions can be removed or commented out as they will not be needed. Then you get variable declaration out of the way.<\/p>\n<pre class=\"lang:c# theme:vs2012\">public Transform lookObject;\r\npublic AudioSource otherAudio;\r\npublic AudioClip stabSound;\r\npublic MeshRenderer mr;<\/pre>\n<p>The <code>Transform<\/code> variable, <code>lookObject<\/code>, will hold the <em>Transform <\/em>information from the <em>Sphere <\/em>object created earlier. One of the iTween animations the project will use will involve the <em>Cube <\/em>looking at the <em>Sphere<\/em>, but in order to do that, it will need to know where the <em>Sphere <\/em>is. Following this is the <code>otherAudio<\/code> variable, which will reference <em>SoundManager<\/em>&#8216;s <em>AudioSource <\/em>component and <code>stabSound<\/code> which, despite the violent sounding name, has nothing to do with sharp objects. This is in reference to a sound that will be played using iTween&#8217;s <em>Stab <\/em>command, which will be covered later. Finally, there&#8217;s <code>mr<\/code>, which will contain information about the <em>Cube <\/em>object&#8217;s <em>MeshRenderer <\/em>component. This is how the object&#8217;s colour will be reset when you want to stop an iTween animation.<\/p>\n<p>At this point, the script should look similar to Figure 12.<\/p>\n<p class=\"caption\"><img loading=\"lazy\" decoding=\"async\" width=\"384\" height=\"256\" class=\"wp-image-85280\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/09\/word-image-11.jpeg\" \/><\/p>\n<p class=\"caption\">Figure 12: Beginning of <em>Actions <\/em>script.<\/p>\n<p>With everything prepared, the first thing to do is to develop a UI that will display some buttons and text. Ordinarily you might do this in the Unity Editor rather than in code, but for this project using Unity&#8217;s <code>OnGUI<\/code> method will work nicely. But what does <code>OnGUI<\/code> do? <code>OnGUI<\/code> is a method that handles the creation and execution of UI elements and functionality. It&#8217;s a helpful method for when you need a quick UI or to create showcases such as this.<\/p>\n<pre class=\"lang:c# theme:vs2012\">private void OnGUI()\r\n{\r\n\tGUI.Label(new Rect(600, 10, 150, 50), \"# of iTweens running: \" \r\n            + iTween.Count());\r\n}<\/pre>\n<p>After creating the method, the very first thing done is to create a GUI label. A new rectangle is created in this label that will contain some text. This text will display the number of iTween animations currently running using iTween&#8217;s <code>Count<\/code> method. Now several buttons will be created in the <code>OnGUI<\/code> function that the user can press to begin an iTween animation. The first three all relate to an object&#8217;s transform and look like this:<\/p>\n<pre class=\"lang:c# theme:vs2012\">if (GUI.Button(new Rect(10, 10, 100, 20), \"Move Object\"))\r\n\tiTween.MoveBy(gameObject, iTween.Hash(\"x\", 4, \"easeType\", \r\n        \"easeInOutExpo\", \"loopType\", \"pingPong\", \"delay\", 0.3f, \r\n        \"onStart\", \"PlaySound\"));\r\nif (GUI.Button(new Rect(10, 30, 100, 20), \"Rotate Object\"))\r\n\tiTween.RotateBy(gameObject, iTween.Hash(\"y\", 0.5f, \"easeType\", \r\n        \"easeInOutExpo\", \"loopType\", \"pingPong\", \"delay\", 0.5f));\r\nif (GUI.Button(new Rect(10, 50, 100, 20), \"Scale Object\"))\r\n\tiTween.ScaleBy(gameObject, iTween.Hash(\"x\", 3, \"y\", 3, \"z\", 3, \r\n        \"easeType\", \"easeInOutExpo\", \"loopType\", \"pingPong\", \r\n        \"delay\", 1f));<\/pre>\n<p>Now would be a good time to break down what all of these are doing. First, you&#8217;re creating a new button in code and checking if this button is clicked. The button&#8217;s size and position are defined in the <code>new<\/code> <code>Rect<\/code><em>&#8216;s <\/em>parameters. Some text is created within this rectangle, and then you get to the button&#8217;s functionality the next line down. As you can see, all three buttons operate very similarly to each other. You first select which iTween action you wish to take, followed by setting which object should perform this action. In this case, the object is the one this script will be attached to, so the code just says <code>gameObject<\/code>.<\/p>\n<p>Next, an iTween hash is defined. This is where you set what part of an object is to be animated, such as the <em>x-<\/em>axis, and how it will animate. In the <code>MoveBy<\/code> iTween for instance, you&#8217;ve told Unity to move the object on its <em>x-<\/em>axis to four and set the <code>easeType<\/code> to <code>easeInOutExpo<\/code>. The <code>easeType<\/code> in an iTween, as the name implies, is how the object will ease in and out of its animation. There is also <code>loopType<\/code>, which has been set to <code>pingPong<\/code> in all three animations. Using <code>pingPong<\/code> will cause the animation to play forward then backward over and over. You can also set the <code>loopType<\/code> to <code>none<\/code> and <code>loop<\/code>. Next is <code>delay<\/code> which allows you to set how much time you want to pass before the animation begins, and finally in <code>MoveBy<\/code><em>, <\/em>you have an <code>onStart<\/code> parameter. <code>OnStart<\/code> is where you can define a method to perform upon the start of an iTween, in this case a currently undefined method named <code>PlaySound<\/code>. Speaking of which, perhaps now is a good time to create this method.<\/p>\n<pre class=\"lang:c# theme:vs2012 \">void PlaySound()\r\n{\r\n\tiTween.Stab(gameObject, iTween.Hash(\"audioClip\", stabSound, \r\n              \"audioSource\", otherAudio, \"volume\", 1, \"delay\", \r\n              0.35f, \"loopType\", \"none\"));\r\n}<\/pre>\n<p>A new iTween has been introduced, named <code>Stab<\/code>. Admittedly it sounds rather vicious, but all it does is play a sound effect of your choosing. Like the earlier iTweens, <code>Stab<\/code> first asks you to select a game object then create a hash. This time the hash has you setting <code>audioClip<\/code> to the previously defined <code>stabSound<\/code>, which will come from the <code>otherAudio<\/code> <code>AudioSource<\/code>. The volume is set to 1, a delay is set, and Unity is told that there will be no looping. At this point, the script should so far look like the one in Figure 13.<\/p>\n<p class=\"caption\"><img loading=\"lazy\" decoding=\"async\" width=\"1156\" height=\"452\" class=\"wp-image-85281\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/09\/word-image-12.jpeg\" \/><\/p>\n<p class=\"caption\">Figure 13: <em>OnGUI <\/em>and <em>PlaySound <\/em>methods.<\/p>\n<p>Returning to the <code>OnGUI<\/code> method, the next few iTweens will deal with changing an object&#8217;s appearance as well as playing with the game&#8217;s music.<\/p>\n<pre class=\"lang:c# theme:vs2012 \">if (GUI.Button(new Rect(10, 70, 100, 20), \"Color Object\"))\r\n\tiTween.ColorTo(gameObject, iTween.Hash(\"r\", 5, \"easeType\", \r\n        \"easeInOutExpo\", \"loopType\", \"pingPong\", \"delay\", 0.5f));\r\nif (GUI.Button(new Rect(10, 90, 100, 20), \"Change Pitch\"))\r\n\tiTween.AudioTo(gameObject, iTween.Hash(\"pitch\", 0, \"delay\", \r\n        1, \"time\", 3, \"easeType\", \"easeInOutExpo\", \"onComplete\", \r\n        \"ReturnAudio\"));\r\nif (GUI.Button(new Rect(150, 10, 100, 20), \"Fade Object\"))\r\n\tiTween.FadeTo(gameObject, iTween.Hash(\"alpha\", 0, \"time\", 1, \r\n        \"delay\", 0.35f, \"easeType\", \"easeInOutExpo\", \"loopType\", \r\n        \"pingPong\"));<\/pre>\n<p>Perhaps you&#8217;re noticing a pattern here? Barring a few key differences, almost every iTween is structured the same way. The most significant difference is in which value is being changed. For example, in <code>ColorTo<\/code>, the object&#8217;s <code>r<\/code> (red) value is changing while <code>RotateBy<\/code> is adjusting the object&#8217;s <em>y <\/em>rotation value. This is one more reason for iTween&#8217;s appeal \u2013 that being the universal rules to using an iTween command. There are of course some exceptions such as <code>Stab<\/code>, and you can add or remove complexity of the commands on a whim like what was done with the <code>AudioTo<\/code> line. In this iTween, the opposite of the <code>MoveBy's<\/code> <code>onStart<\/code> parameter is being performed, <code>onComplete<\/code>. Once this iTween has finished its task, it will perform the <code>ReturnAudio<\/code> method. That method performs a slightly different iTween that demonstrates how you can control as much or as little of the iTween command as you wish.<\/p>\n<pre class=\"lang:c# theme:vs2012\">void ReturnAudio()\r\n{\r\n\tiTween.AudioTo(gameObject, iTween.Hash(\"pitch\", 1, \"time\",\r\n        1.6, \"delay\", 0.5f));\r\n}<\/pre>\n<p>There are a few other animations this project is looking to demonstrate before the script is complete. The following code shows how you can create an animation that rapidly shakes the object, \u201cpunches\u201d the object, and how an object can be made to look at another point in the world. Once again, all this is to be entered in the <code>OnGUI<\/code> method.<\/p>\n<pre class=\"lang:c# theme:vs2012\">if (GUI.Button(new Rect(150, 30, 100, 20), \"Look Object\"))\r\n\tiTween.LookTo(gameObject, iTween.Hash(\"lookTarget\", lookObject,\r\n        \"time\", 1, \"delay\", 1, \"easeType\", \"linear\", \"loopType\", \r\n        \"pingPong\"));\r\nif (GUI.Button(new Rect(150, 50, 100, 20), \"Shake Object\"))\r\n\tiTween.ShakePosition(gameObject, iTween.Hash(\"amount\", \r\n        new Vector3(2, 2, 2), \"time\", 2, \"delay\", 0.5f, \"easeType\", \r\n        \"easeInBounce\", \"loopType\", \"loop\"));\r\nif (GUI.Button(new Rect(150, 70, 100, 20), \"Punch Object\"))\r\n\tiTween.PunchPosition(gameObject, iTween.Hash(\"amount\", \r\n        new Vector3(5, 5, 5), \"time\", 2, \"delay\", 1, \r\n        \"loopType\", \"loop\"));<\/pre>\n<p>All of these animations involve feeding the code some kind of position or transform data to complete the task. For instance, <code>LookTo<\/code> has you giving <code>lookTarget<\/code> the transform data for <code>lookObject<\/code>, also known as the <code>Sphere<\/code> object created earlier. Similarly, <code>ShakePosition<\/code> and <code>PunchPosition<\/code> ask for <code>Vector3<\/code> data to accomplish their goals. Now, the script is mostly finished but you might be wondering what one can do about all these looping animations. Naturally, there&#8217;s a way to stop all these animations immediately if so desired.<\/p>\n<pre class=\"lang:c# theme:vs2012 \">if (GUI.Button(new Rect(450, 10, 110, 20), \"Stop Everything\"))\r\n{\r\n\tiTween.Stop();\r\n\ttransform.position = new Vector3(0, 0, 0);\r\n\ttransform.localScale = new Vector3(2, 2, 2);\r\n\ttransform.eulerAngles = new Vector3(-10, 45, -30);\r\n\tmr.material.color = Color.white;\r\n\tiTween.AudioTo(gameObject, iTween.Hash(\"pitch\", 1, \r\n            \"time\", 1.6, \"delay\", 0.5f));\r\n}<\/pre>\n<p>The code, in particular, is <code>iTween.Stop<\/code> which, you guessed it, stops all currently running iTweens. The remainder of the code resets the object&#8217;s position, scale, rotation, and colour. It also uses the same <code>AudioTo<\/code> command from the <code>ReturnAudio<\/code> method in case this is pressed in the middle of the audio&#8217;s pitch being brought down. Now that the script is complete, the only task left to do is save the script and go back to the Unity editor to finish some last-minute tasks.<\/p>\n<h2>Finishing the Project<\/h2>\n<p>Very little remains to be done before the project is complete. First, you&#8217;ll need to attach the <em>Actions <\/em>script to the <em>Cube <\/em>object. To make it easier to work with the Cube properties, you might want to lock the inspector. Figure 14 shows where to drag the Actions script.<\/p>\n<p class=\"caption\"><img loading=\"lazy\" decoding=\"async\" width=\"912\" height=\"192\" class=\"wp-image-85282\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/09\/word-image-13.jpeg\" \/><\/p>\n<p class=\"caption\">Figure 14: Attaching the <em>Actions <\/em>script component to <em>Cube<\/em><\/p>\n<p>Notice an <em>AudioSource <\/em>component is attached to the Cube at the same time thanks to the <em>RequireComponent <\/em>class attribute from earlier.<\/p>\n<p>In the <em>AudioSource <\/em>component, place a song of your choice into the <em>AudioClip <\/em>field, as shown in Figure 15. This is the song that will receive a pitch change thanks to the <em>AudioTo <\/em>command from earlier. You can also set <em>Loop <\/em>to true if you wish, but it is not required.<\/p>\n<p class=\"caption\"><img loading=\"lazy\" decoding=\"async\" width=\"838\" height=\"169\" class=\"wp-image-85283\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/09\/word-image-14.jpeg\" \/><\/p>\n<p class=\"caption\">Figure 15: Selecting a music track<\/p>\n<p>All that&#8217;s left is to fill in the fields from the <em>Action <\/em>script component. <em>Look Object <\/em>will be given the <em>Sphere <\/em>object&#8217;s <em>Transform <\/em>data, while <em>SoundManager <\/em>will fill the <em>Other Audio <\/em>field, as shown in Figure 16.<\/p>\n<p class=\"caption\"><img loading=\"lazy\" decoding=\"async\" width=\"931\" height=\"504\" class=\"wp-image-85284\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/09\/word-image-15.jpeg\" \/><\/p>\n<p class=\"caption\">Figure 16: Filling <em>Look Object <\/em>and <em>Other Audio <\/em>fields<\/p>\n<p><em>Stab Sound <\/em>will be a sound effect of your choosing. Like when selecting the music for <em>Cube<\/em>&#8216;s <em>AudioSource <\/em>component, you&#8217;ll need to drag some audio file from the <em>Assets <\/em>window into <em>Stab Sound.<\/em> Finally, <em>Mr <\/em>is filled by dragging <em>Cube&#8217;s Mesh Renderer <\/em>component into the <em>Mr <\/em>field shown in Figure 16.<\/p>\n<p class=\"caption\"><img loading=\"lazy\" decoding=\"async\" width=\"592\" height=\"655\" class=\"wp-image-85285\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/09\/word-image-16.jpeg\" \/><\/p>\n<p class=\"caption\">Figure 17: Filling the <em>Mr <\/em>field<\/p>\n<p>Once all the fields are filled, you are ready to test out the project. The GUI you created in code will instantly appear and clicking any of the buttons will perform their respective tasks. Try mixing and matching iTweens so, as an example, you can have it changing size while rotating. You can also adjust the position of the <em>Sphere <\/em>object to get a slightly different result when clicking the <em>Look Object <\/em>button. Figure 18 shows the GUI once you are playing the game.<\/p>\n<p class=\"caption\"><img loading=\"lazy\" decoding=\"async\" width=\"880\" height=\"386\" class=\"wp-image-85286\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/09\/word-image-17.jpeg\" \/><\/p>\n<p class=\"caption\">Figure 18: The finished project<\/p>\n<h2>Conclusion<\/h2>\n<p>It almost feels like cheating when using iTween, doesn&#8217;t it? What&#8217;s normally a three to five-step process can be simplified into one step, consisting of one line of code. The examples shown here are just a small sampling of what iTween can do. You can check out <a href=\"http:\/\/www.pixelplacement.com\/itween\/index.php\">iTween&#8217;s website<\/a> to see more examples as well as some documentation showing all the different commands available to you. Whether it be used for prototyping or giving your current development a nice boost, there&#8217;s plenty of reason to consider having the iTween plugin on hand for any project.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Video games often contain animation of the objects and characters, but how is that accomplished? In this article, Lance Talbert explains how a Unity plugin called iTween can make creating animation easy. &hellip;<\/p>\n","protected":false},"author":317499,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[143538,53],"tags":[],"coauthors":[52549],"class_list":["post-85268","post","type-post","status-publish","format-standard","hentry","category-dotnet-development","category-featured"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/85268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/317499"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=85268"}],"version-history":[{"count":5,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/85268\/revisions"}],"predecessor-version":[{"id":85288,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/85268\/revisions\/85288"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=85268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=85268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=85268"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=85268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}