digispired ii project1(updated) - ms. ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... ·...
TRANSCRIPT
![Page 1: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/1.jpg)
Figure 27
Right below the Min and Max Size we have Min Energy and Max Energy. These two options give the minimum lifetime of each particle, measured in seconds when created. Let’s change the Min Energy to 0.5 and the Max Energy to 1. We also have the Max Emission and the Min Emission. This option gives the number of particles that will be spawned every second. Let’s change the Min Emission to 15 and the Max Emission to 30. Also make sure that Rnd Rotation, Simulate in Worldspace, and One Shot is checked. Particle Animator Particle Animators move your particles over time. You can use them to apply wind, drag & color cycling to your particle systems.
![Page 2: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/2.jpg)
Figure 28 The Particle Animator Inspector
Properties Does Animate Color If enabled, particles cycle their color over their lifetime.
Color Animation The 5 colors particles go through. All particles cycle over this - if some have a shorter life span than others, they will animate faster.
World Rotation Axis An optional world-space axis the particles rotate around. Use this to make advanced spell effects or give caustic bubbles some life.
Local Rotation Axis An optional local-space axis the particles rotate around. Use this to make advanced spell effects or give caustic bubbles some life.
Size Grow Use this to make particles grow in size over their lifetime. As randomized forces will spread your particles out, it is often nice to make them grow in size so they don't fall apart. Use this to make smoke rise upwards, to simulate wind, etc.
Rnd Force A random force added to particles every frame. Use this to make smoke become more alive.
Force The force being applied every frame to the particles, measure relative to the world.
Damping How much particles are slowed every frame. A value of 1 gives no damping, while less makes them slow down.
Autodestruct If enabled, the GameObject attached to the Particle Animator will be destroyed when all particles disappear.
Details Particle Animators allow your particle systems to be dynamic. They allow you to change the color of your particles, apply forces and rotation, and choose to destroy them when they are finished emitting. To add this component to our project we will go to: Component > Effects > Legacy Particle >Particle Animator. Let’s go to the Color Animation and change them to match the colors in the screen shot below. Let’s change the Damping option to 0.25. You may notice that your particle may not be the color you set it to and it may be a pink color but we will fix that shortly.
![Page 3: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/3.jpg)
Figure 29
Particle Renderer The Particle Renderer renders the Particle System on screen.
Figure 30 The Particle Renderer Inspector
![Page 4: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/4.jpg)
Properties
Materials Reference to a list of Materials that will be displayed in the position of each individual particle.
Camera Velocity Scale The amount of stretching that is applied to the Particles based on Camera movement.
Stretch Particles Determines how the particles are rendered.
Billboard The particles are rendered as if facing the camera.
Stretched The particles are facing the direction they are moving.
SortedBillboard The particles are sorted by depth. Use this when using a blending material.
VerticalBillboard All particles are aligned flat along the X/Z axes.
HorizontalBillboard All particles are aligned flat along the X/Y axes.
Length Scale If Stretch Particles is set to Stretched, this value determines how long the particles are in their direction of motion.
Velocity Scale If Stretch Particles is set to Stretched, this value determines the rate at which particles will be stretched, based on their movement speed.
UV Animation If either of these are set, the UV coordinates of the particles will be generated for use with a tile animated texture. See the section on Animated Textures below.
X Tile Number of frames located across the X axis.
Y Tile Number of frames located across the Y axis.
Cycles How many times to loop the animation sequence.
Details
Particle Renderers are required for any Particle Systems to be displayed on the screen To add the Particle Window to our inspector window we will go to the following Component > Effects > Legacy Particle >Particle Renderer. Now we want to actually see our Particle Animator color scheme that we just changed. If we take a look in the Particle Renderer window we see the Materials Options. Let’s expand that option and change Element 0 to Default. Once you change this you will see the actual color that you changed in your particle animator instead of the pink. See screen shot below for comparison
![Page 5: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/5.jpg)
Figure 31 Figure 32
The last couple of options we will change in the Particle Render is the Stretched Particles option from Billboard to Stretched. As with the objects we created before we had to create a Prefab, so we will do that now for our explosion. So let’s go to the Project window go to Create > Prefab. Let’s rename this prefab “prefabExplosion” and drag the “explosion” particle that we created. We can use this in the future. We have created all the assets we need except the audio files so this is what we will do next.
Assets Audio Now we will import some audio files that we can use for our explosion. For this project we need to find 3 audio sounds that mimic and explosion. We are going to have about 3 different types that we can cycle through for sound effects. To do that we can load them through the project window. We can right click and select Import New Asset and now navigate to the location of those sounds and import them. Once you have imported the files you should see them in the project window. Let’s go ahead and rename these three files the following: audioExplosion1 audioExplosion2 audioExplosion3. You can also drag and drop the file from another location into the project window. Let’s preview the sound of our explosion in the inspector window. Assets Scenes Now that we have created all the assets for the project we will now create the scene files that all of these assets will go into. So we have just a couple of scenes we will be working with and creating. We have one which is the scene or the level the game actually takes place on. Then we have a few more that are simply the screens that are going to hold all of our menu information; WinScreen or LoseScreen. So to create those screens we can start off with one just blank scene. The first thing we want to do is go to : File > New Scene. You will see here the only thing we have is our main camera
![Page 6: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/6.jpg)
Figure 33
Once we have done this we will go to our hierarchy and select Main Camera and make some changes here. We will change the X to 0, Y to 0 and leave Z -10. Now let’s change the Projection from “Perspective” to “Orthographic”. Let’s go ahead and drag and drop the prefabEnemyCircle into our Hierarchy Window. Now we are ready to create several scenes. The first scene we want to create is sceneLevel1. This part is fairly difficult, but let’s try to get our scene to look like this.
![Page 7: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/7.jpg)
Figure 34
Now that we have this setup we want to try and save out all of the files that we need. Let’s go to File > Save Scene and let’s go ahead and save this scene “sceneLevel1”. Let’s now go back in and save a few more scenes but instead of selecting File > Save we will now do File > Save as and save the following: sceneScreenLose sceneScreenMainMenu sceneScreenWin Now we have all the scenes we need to work inside our Game Project. And each scene has its own camera. Now what we want to do now is start assigning the scripts to the each one of the cameras in each one of the scenes.
![Page 8: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/8.jpg)
Figure 35
Now we need to make a few more changes. So let’s first select sceneScreenWin. Let’s double click on this and now the main camera should show up. Let’s go ahead and drag and drop the scriptScreenWin script here and save it (ctrl +s). Let’s also do the same for the following: Scene Script sceneScreenLose scriptScreenLose sceneScreenWin scriptScreenWin sceneScreenMainMenu scriptScreenMainMenu Now for sceneLevel1 we will not drag and drop any scripts, but we can drag and drop our prefabEnemyCircle and prefabEnemySquare in this box. Make sure to save this.
![Page 9: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/9.jpg)
Figure 36
Scripting Now that we are done creating Assets, we have are project ready and set up to go. Now we will work on adding functionality to make our game work. Now we want to adjust the layout of our window so let’s go ahead and make a few changes. Let’s make our screen resemble the screen below
![Page 10: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/10.jpg)
Figure 37
The first thing we want to do is open up our Script Editor provided by Unity. To open the default Script Editor provided by Unity we will go to the Project Window and double click “scriptPlayer”. We should now have a window that looks like the one below.
![Page 11: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/11.jpg)
Figure 38
Now we want to open our script reference manual to help us out with writing scripts. To access this manual we will go to our Unity 3d Window and go to Help > Scripting Reference. Take a moment to read this so you can be familiar with how scripting works in Unity3d.
![Page 12: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/12.jpg)
Figure 39
Scripting Player Input The first script that we want to work with is our Player Script (“scriptPlayer”) The player script is the place where we add functionality for the player to interact with the gaming environment. The player script will allow us to use the mouse button and perform certain actions for the game we are playing. Before we get started with actually writing the script let’s take a look at our Project Description again. The Project Description file will allow us to have more structure to what we are doing in the project. For example let’s at the High Concept of the game
![Page 13: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/13.jpg)
Figure 40
In our description of the concept of the game we say that we want a high speed mouse clicking game, using the mouse, click on and destroy as many shapes as you can. So by this we know that we must write some type of function or create some portion in our script to perform this action. We also have controls that say use the left mouse button to select on the shapes and destroy them. So it seems like we are using a left mouse button to do this. So let’s start up by opening our Script Editor and add a few comments. So the first thing we want to do is make a quick comment in our editor about what we want to do. Type the following in the editor: function Update () { //use the mouse button to select on GameObjects in the scene }
So what we have done is just created a comment. When writing scripts or doing any type of program the “//” is typically used as comments, which means that this line of code will not execute. It is only there for reference purposes. So basically this comment tells us that this is the main functionality that we will need. We need to be able to use the mouse button to select on game objects in the scene and from this point we will figure out how to do it. At this point we may not know how to do this or how to get this action but we can use our manual to help us out. We can go into this reference manual and do some research to figure out what we need to do. Before we do this we will do one more thing to our script code. Type the following below:
![Page 14: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/14.jpg)
// Player Script // Inspector Variables // Private Variables. function Update () { //use the mouse button to select on GameObjects in the scene }
We added some more comments which we will discuss later if necessary. So now we will open the Scripting Manual and type “mouseButton” So let take a look of the search results.
Figure 41
So if we recall what we have in our “Problem Description” we will see that we need to use the left mouse button to select on shapes. The second option from our results says “Input GetMouseButtonDown “. This option returns true during the frame the user pressed the given mouse button. So let’s go ahead and select this option and see what we have.
![Page 15: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/15.jpg)
Figure 42
So according to the results this seems like it may be good for our script. Let’s go ahead and apply this information to our script. We will go ahead and write the following conditional statement: // Player Script // Inspector Variables // Private Variables. function Update () { //use the mouse button to select on GameObjects in the scene if (Input.GetMouseButtonDown (0)) { print("Yes the button works!"); } }
Let’s save this one. You can save this file by pressing ctrl + s. Let make a few changes before we proceed. Let’s take a look in our project window. Let’s go ahead and drag the prefabEnemyCircle and the prefabEnemySquare to the Hierarchy Window. Let’s also go to Create in the Hierarchy Window and create Directional Light. Our screen should resemble the one below:
Conditional Argument: The
button we want is
zero
Test
![Page 16: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/16.jpg)
Figure 43
Now if we recall, inside the scene we do not have a spot for the “playerScript”. This script is not assigned any object yet. So let’s go ahead and create an Empty Game Object. Go to GameObject > Create Empty. Let’s label this Game Object “playerObject”. Now let’s drag the “playerScript” up to the Inspector Window. Now we can actually use this script. Go ahead and click the play button at the top and go down to the game view and left click and if we look at the console you will be able to see the message “Yes The Button Works!”
![Page 17: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/17.jpg)
Figure 44
Scripting Player RayCast The next thing we want to find out is that if we actually hit the button how do we find that object when that button is pushed. So now we will add more functionality to this project. Now we want to know if we have hit the object. We want to cast a ray from the Camera out into the scene and where in that scene depending on where my mouse is and if there is anything that it intersects with. So now let’s do more research. Go to our Scripting manual and do a search for raycast
![Page 18: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/18.jpg)
Figure 45
In our search we have all types of options but our best option would be the first “RaycastHit”. This option is used to get information back from a raycast.
Figure 46
![Page 19: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/19.jpg)
So as you can we have See Also: Physics.Raycast, Physics.Linecast, Physics.RaycastAll. Let’s choose the first option and see what we have.
Figure 47
So here we have some information that can help us. Take a look at this information for a moment. So let’s go back to our script and see what we can add from our research. Let’s type in the following. We will start off my making a few variables. / Player Script // Inspector Variables // Private Variables. function Update () { //use the mouse button to select on GameObjects in the scene if (Input.GetMouseButtonDown(0)) { print("Yes the button works!"); var hit :RaycastHit; var ray :Ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast(ray, hit, 100.0)) { print("You hit an object"); }
![Page 20: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/20.jpg)
} }
Figure 48
Now if you notice when you hit left click anywhere on the screen you see “Yes the button works”. If you also notice when you hit the object we get a print out of “You hit an object”. Scripting Player Random Position So checking to see if the object is what we want it to be we can start by looking into things like the tag. We can tag our object with a certain name and then if that object has that name then we can do something to it, but if it does not we can pass it on. So with that we will need to write another conditional statement that says “if this object has this name, then do something to it”. So let’s open up our editor and write another conditional statement. Add the line in red below. // Player Script // Inspector Variables // Private Variables. function Update () { //use the mouse button to select on GameObjects in the scene if (Input.GetMouseButtonDown(0)) { print("Yes the button works!"); var hit :RaycastHit; var ray :Ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast(ray, hit, 100.0)) { if(hit.transform.tag == "enemy") {
![Page 21: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/21.jpg)
print("You hit an object"); } } } }
Let’s save this . We still want to print out “You hit an object” just to make sure it works. Let’s go back to Unity and select on our object
Figure 49
When we select our object we should see the information in the inspector window. Let’s create a tag and name it “enemy”. Now to create a tab, let’s take a look at our inspector window. You will see a tag option and next to it you will see “Untagged”. Let’s click there. Now we will go to “Add Tag “
![Page 22: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/22.jpg)
Figure 50
Now when we select add tag we will see a window like the Figure below.
![Page 23: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/23.jpg)
Figure 51
By default in the Tag Manager “Tags’ is rolled up so let’s click the arrow and expand. You should have the display below
![Page 24: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/24.jpg)
Figure 52
Let’s change the size to 2 and select Element 0 and name this tag “enemy”. Now the tag has been created. Now let’s go back onto your object and select on your object in the inspector window. Now we can go back to where we set up the tag and assign the enemy tag to our prefabEnemyCircle. Now let’s press play on our player. Notice that we when randomly click anywhere we get “Yes the button works” but is we click on our object we get “You hit an object” and “Yes the button Works. Try clicking on the square object and see what happens. We get “Yes The Button Works.” So now we know this has been done correctly because we only get “You hit an object” when we click on the circle. Now let’s actually do something to the object to make it more interactive once we click on it. Let’s first look at moving this object around. Now one of the things we want to do is make this object move around in different areas randomly. So let’s go back to our editor and also open up our reference manual. We now want to make a random number so let’s search for “Random”
![Page 25: Digispired II Project1(Updated) - Ms. Ciokanciokan.weebly.com/uploads/2/8/2/6/2826457/digi... · Use this to make advanced spell effects or give caustic bubbles some life. Size Grow](https://reader035.vdocuments.net/reader035/viewer/2022081611/5f027a8a7e708231d4047683/html5/thumbnails/25.jpg)
Figure 53
Let’s choose Random.Range and take a look at this. Now let’s go back to our script editor and type in the following and save it. // Player Script // Inspector Variables // Private Variables. function Update () { //use the mouse button to select on GameObjects in the scene if (Input.GetMouseButtonDown(0)) { print("Yes the button works!"); var hit :RaycastHit; var ray :Ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast(ray, hit, 100.0)) { if(hit.transform.tag == "enemy") { var position = Vector 3(Random.Range(-6,6),Random.Range(-4,4),0); hit.transform.position = position; print("You hit an object"); } } } }
Now let’s go back to Unity 3d and start our player and see what happens