# Mod the Cube

Summary : In this exercise, you'll be challenged to modify a provided script to change the behavior of an object it's applied to.

<details id="bkmrk-type%3Atutorial-level%3A"><summary></summary>

<div class="subtitle-item_xpaEsup9">Type:Tutorial</div><div class="subtitle-item_xpaEsup9"><div class="dot_2bxnxodK">  
</div>Level:Beginner</div><div class="subtitle-item_xpaEsup9"><div class="dot_2bxnxodK">  
</div><div class="tag_1zONFo0R tag-points">Xp: 60  
</div></div><div class="subtitle-item_xpaEsup9"><div class="duration-label_68-m16F8"></div><div class="duration-label_68-m16F8"><span class="minute">Estimated time to complete: 30 Mins  
  
Materials: [ModTheCubeChallengeAssets.zip](https://connect-prd-cdn.unity.com/20201026/b3aa8c3a-1cb7-49eb-b835-aa4eefc8b1e0/ModTheCubeChallengeAssets.zip)</span></div></div><div class="duration-label_68-m16F8">  
</div><div class="duration-label_68-m16F8">  
</div></details>#### 1.Overview

In this mission you learned how to open, read, and modify scripts. You practiced fundamental programming challenges, and hopefully you’re starting to feel comfortable with basic scripting. In this exercise, you’ll be tasked with modifying the behavior of an already existing script. We’re leaving this challenge open-ended, so now’s the time to get creative!

#### 2.Download the provided assets and import them into a new Unity Project

1. <span data-offset-key="dn9t9-0-1"><span data-text="true">Download </span></span>[<span data-offset-key="dn9t9-1-0" style="text-decoration: underline;"><span data-text="true">ModTheCubeChallengeAssets.zip</span></span>](https://connect-prd-cdn.unity.com/20201026/b3aa8c3a-1cb7-49eb-b835-aa4eefc8b1e0/ModTheCubeChallengeAssets.zip?_ga=2.132173388.37272804.1639415162-1635354840.1616306530)<span data-offset-key="dn9t9-2-0"><span data-text="true">.</span></span>
2. <span data-offset-key="164tu-0-1"><span data-text="true">To unzip the contents of the folder, right-click the folder and select </span></span><span data-offset-key="164tu-0-2" style="font-weight: bold;"><span data-text="true">Extract All</span></span><span data-offset-key="164tu-0-3"><span data-text="true"> (macOS: double-click the zipped folder). Inside you will find ModTheCube.unitypackage.  
      
    </span></span><div class="" data-block="true" data-editor="editorBody_1" data-offset-key="bj0cc-0-0"><div class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr" data-offset-key="bj0cc-0-0" style="padding-left: 40px;"><span data-offset-key="bj0cc-0-0" style="font-weight: bold;"><span data-text="true">Note: </span></span><span data-offset-key="bj0cc-0-1"><span data-text="true">While it is possible to view the contents of a folder while it’s still zipped, the data is still compressed. Attempting to import the contents of the ModThCubeChallengeAssets folder while it’s still zipped will result in an error message in Unity. Ensure that you have unzipped the folder before proceeding to the next step.</span></span></div></div>
3. [<span data-offset-key="ahmlg-1-0" style="text-decoration: underline;"><span data-text="true">Create a new Unity project</span></span>](https://learn.unity.com/tutorial/project-setup-processes#60f6aedeedbc2a7e96802196)<span data-offset-key="ahmlg-2-0"><span data-text="true"> using the 3D template - remember to use one of the supported versions of Unity (2018.4LTS, 2019.4LTS, or 2020.3LTS).</span></span>
4. [<span data-offset-key="59f4i-1-0" style="text-decoration: underline;"><span data-text="true">Import</span></span>](https://learn.unity.com/tutorial/project-setup-processes#60ed7a91edbc2a002096b762)<span data-offset-key="59f4i-2-0"><span data-text="true"> ModTheCube.unitypackage into your new 3D template project.</span></span>

#### 3.Observe the default script functionality

<span data-offset-key="b0000-0-0"><span data-text="true">Before you begin editing the code, take a few minutes to understand what the script does by default. The imported .unitypackage contains three items: a C# script, a material, and a scene.</span></span>

1. <span data-offset-key="eef54-0-1"><span data-text="true">Open the scene located in the ModTheCube folder. </span></span><span data-offset-key="eef54-0-1"><span data-offset-key="eef54-0-1"><span data-text="true">  
    </span></span></span>[![image.png](https://library.naruzkurai.com/uploads/images/gallery/2023-06/scaled-1680-/KrH0KYxBLzveE7KR-image.png)](https://library.naruzkurai.com/uploads/images/gallery/2023-06/KrH0KYxBLzveE7KR-image.png)
    
    <span data-offset-key="eef54-0-1"><span data-text="true">  
    <span data-offset-key="f095m-0-0">The only thing in the scene aside from the Camera and Directional Light is a cube. Attached to the cube is the script you will be modifying.</span>  
    </span></span>
2. <span data-offset-key="btpsr-0-1"><span data-text="true">Enter Play mode (select the play button on the toolbar) and observe the default behavior of the script assigned to the cube.  
    </span></span><span data-offset-key="aj3c3-0-0"><span data-text="true">When you enter Play mode, you will observe several of the cube’s properties change. All of these changes are hardcoded into the cube.cs script attached to the cube in the scene. This means that the cube will be modified in the same way each time the scene is run.</span></span>

####   


#### 4.Modify the cube.cs script

<span data-offset-key="8tg2q-0-0"><span data-text="true">Now that you understand what the cube script is doing, you can begin to customize it. As previously mentioned, all of the changes the script is making to the cube are specified in the code. It would be easier to control the cube from the Unity Editor instead of editing the script. You can make this possible by changing variables to be public. Public variables appear in the Inspector window where you can modify their values.</span></span>

1. Open the cube.cs script in your code editor and observe the code.
2. Identify at least two changes that you can make to the cube’s behavior. 
    - <span data-offset-key="1c0lq-0-0"><span data-text="true">Change the cube's location (transform).  
        </span></span>
    - <span data-offset-key="1c0lq-0-0"><span data-text="true"><span data-offset-key="2g8b3-0-0">Change the cube's scale.</span></span></span>
    - <span data-offset-key="1c0lq-0-0"><span data-text="true"><span data-offset-key="2g8b3-0-0"><span data-offset-key="8qfr1-0-0">Change the angle at which the cube rotates.</span></span></span></span>
    - <span data-offset-key="1c0lq-0-0"><span data-text="true"><span data-offset-key="2g8b3-0-0"><span data-offset-key="8qfr1-0-0"><span data-offset-key="fbota-0-0">Change the cube’s rotation speed.</span></span></span></span></span>
    - <span data-offset-key="1c0lq-0-0"><span data-text="true"><span data-offset-key="2g8b3-0-0"><span data-offset-key="8qfr1-0-0"><span data-offset-key="fbota-0-0"><span data-offset-key="6pitq-0-0">Change the cube’s material color.</span></span></span></span></span></span>
    - <span data-offset-key="1c0lq-0-0"><span data-text="true"><span data-offset-key="2g8b3-0-0"><span data-offset-key="8qfr1-0-0"><span data-offset-key="fbota-0-0"><span data-offset-key="6pitq-0-0"><span data-offset-key="7c5gt-0-0">Change the cube’s material opacity.</span></span></span></span></span></span></span><span data-offset-key="1c0lq-0-0"><span data-text="true"><span data-offset-key="2g8b3-0-0"><span data-offset-key="8qfr1-0-0"><span data-offset-key="fbota-0-0"><span data-offset-key="6pitq-0-0"><span data-offset-key="1fjc4-0-0">If you’re feeling confident, you can attempt the following as well:</span></span></span></span></span></span></span>
    - <span data-offset-key="1c0lq-0-0"><span data-text="true"><span data-offset-key="2g8b3-0-0"><span data-offset-key="8qfr1-0-0"><span data-offset-key="fbota-0-0"><span data-offset-key="6pitq-0-0"><span data-offset-key="9lqnt-0-0">Modify any of the changes above so they change randomly each time the scene is played.</span></span></span></span></span></span></span>
    - <span data-offset-key="1c0lq-0-0"><span data-text="true"><span data-offset-key="2g8b3-0-0"><span data-offset-key="8qfr1-0-0"><span data-offset-key="fbota-0-0"><span data-offset-key="6pitq-0-0"><span data-offset-key="9lqnt-0-0"><span data-offset-key="f14sc-0-0">Add extra functionality to the cube. For example, how might you change the color of the cube over time?</span></span></span></span></span></span></span></span>
3. <span data-offset-key="at9sh-0-1"><span data-text="true">Implement your planned changes in the code.</span></span>
4. <span data-offset-key="1h0vm-0-1"><span data-text="true">Test the scene regularly as you work to ensure your code is performing as expected. </span></span>

#### 5.Create a WebGL project showing off your modded cube

<span data-offset-key="cefav-0-0"><span data-text="true">Now that you have edited your script and thoroughly tested your changes, your remaining task is to submit your project here and show off your work! You will create a WebGL build of your project, upload it to Unity Play, and then complete this challenge by linking your submission below. </span></span>

1. <span data-offset-key="2u1l6-0-1"><span data-text="true">If you haven’t already done so, frame your camera in the scene so it’s easy to see the cube in the Play view.</span></span>
2. <span data-offset-key="8d4ae-0-1"><span data-text="true">Save your scene.</span></span>
3. <span data-offset-key="f9fu4-0-1"><span data-text="true">Ensure that your version of Unity has WebGL installed. Not sure if it does, or don’t know how to add it? Refer to step 2 of the </span></span>[<span data-offset-key="f9fu4-1-0" style="text-decoration: underline;"><span data-text="true">Create and publish WebGL Builds</span></span>](https://learn.unity.com/tutorial/creating-and-publishing-webgl-builds#601abb0cedbc2a0027bad0e3)<span data-offset-key="f9fu4-2-0"><span data-text="true"> tutorial.</span></span>
4. <span data-offset-key="3ilao-0-1"><span data-text="true"> Install the WebGL Publisher package. This package will allow you to easily publish your project on Unity Play. If you aren’t sure if you have the package or don’t know how to add it, refer to the tutorial linked in the step above.</span></span>
5. <span data-offset-key="5uj3n-0-1"><span data-text="true">Create a WebGL build of your project. This may take a few minutes, depending on your computer. If you need help creating the build, refer to step 4 of </span></span>[<span data-offset-key="5uj3n-1-0" style="text-decoration: underline;"><span data-text="true">Create and publish WebGL builds</span></span>](https://learn.unity.com/tutorial/creating-and-publishing-webgl-builds#601abbf4edbc2a00203665e6)<span data-offset-key="5uj3n-2-0"><span data-text="true">.</span></span>
6. <span data-offset-key="7cp6u-0-1"><span data-text="true">Publish your WebGL build on Unity Play. If you need help publishing on Unity Play, refer to step 6 of </span></span>[<span data-offset-key="7cp6u-1-0" style="text-decoration: underline;"><span data-text="true">Create and publish WebGL builds</span></span>](https://learn.unity.com/tutorial/creating-and-publishing-webgl-builds#601abce4edbc2a00214a1278)<span data-offset-key="7cp6u-2-0"><span data-text="true">.</span></span>
7. <span data-offset-key="3snaa-0-1"><span data-text="true">Copy your Unity Play link, and paste it below! </span></span>

#### 6.Criteria

<span data-offset-key="drsqg-0-0"><span data-text="true">You’ll know you’re successful if you’ve met these criteria:</span></span>

- <span data-offset-key="b067p-0-0"><span data-text="true">You’ve modified the cube script so that at least two changes are made to the cube’s behavior.</span></span>
- <span data-offset-key="8nr2p-0-0"><span data-text="true">You’ve created a WebGL build of your project.</span></span>
- <span data-offset-key="dlo9h-0-0"><span data-text="true">You’ve uploaded the WebGL build to Unity Play.</span></span>
- <span data-offset-key="7gbl0-0-0"><span data-text="true">You’ve copied your Unity Play link for submission.</span></span>

#### 7.Next steps  


<span data-offset-key="fil2r-0-0"><span data-text="true">Congratulations on completing the first mission in Junior Programmer! You now have a strong foundational understanding of the structure of basic scripts and how to make simple modifications. As you continue through the pathway, consider taking time to think about how you might modify other scripts you encounter to customize them to your liking. Sometimes the best way to reinforce what you’ve learned is to apply it in different ways on your own! </span></span>

#### 8.Submission

  
<span data-offset-key="974ij-0-0"><span data-text="true">Paste your Unity Play link below! </span></span>  
[link to the original unity course](https://learn.unity.com/tutorial/mod-the-cube?uv=2021.3&labelRequired=true&pathwayId=5f7e17e1edbc2a5ec21a20af&missionId=5f71fe63edbc2a00200e9de0 "link to unity course")

<div class="left-column_1GmmpXrG middle-column-overview" id="bkmrk--1"><div class="section-wrap_33eSsj8g download-wrap_b9v8upbH default">  
</div></div>