GameCamp! by ModLab Josef Nguyen and Amanda Phillips, facilitators Genre Bending.
GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®
-
Upload
jasmin-chambers -
Category
Documents
-
view
234 -
download
5
Transcript of GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®
![Page 1: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/1.jpg)
GameCamp! andGame Dev @ DavisIntroduction to Scripting in Unity®
![Page 2: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/2.jpg)
Create Standard 3D Project
![Page 3: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/3.jpg)
Unity® Interface
![Page 4: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/4.jpg)
Create Cube▼Create
►3D Object ►Cube
![Page 5: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/5.jpg)
Add a Script ComponentName: ColorChanger
public Color color;
Void Start{GetComponent<MeshRenderer>().material.color = color;}
![Page 6: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/6.jpg)
TestSee that while the cube is white in the scene view, when the game runs, the cube changes to the assigned color
![Page 7: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/7.jpg)
Add Another Script ComponentName: Mover
public Vector3 movementVector = Vector3.right;
Void Update{transform.position += movementVector * Time.deltaTime;}
![Page 8: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/8.jpg)
TestNotice that the cube only moves to the right indefinitely
![Page 9: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/9.jpg)
Add More Code to Moverprivate Vector3 startPosition;
Void Start{startPosition = transform.position;}
![Page 10: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/10.jpg)
Add More Code to MoverAfter transform.position in update
if (transform.position.x > startPosition.x + 1)movementVector = Vector3.left;else if (transform.position.x < startPosition.x – 1)movementVector = Vector3.right;
![Page 11: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/11.jpg)
TestNow the cube should move back and forth when the game is run
![Page 12: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/12.jpg)
Make the Scripts InteractMake changes to ColorChanger
public Color color1;public Color color2;
![Page 13: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/13.jpg)
Make the Scripts InteractRevise the Start code:
Delete: GetComponent<MeshRenderer>().material.color = color;
![Page 14: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/14.jpg)
Make the Scripts Interactvoid Update () {
if (GetComponent<Mover>().movementVector == Vector3.left)GetComponent<MeshRenderer>().material.color = color1;
elseGetcomponent<MeshRenderer>().material.color = color2;
}
![Page 15: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/15.jpg)
TestThe cube should move back and forth and also change colors when changing directions
![Page 16: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/16.jpg)
Create PrefabRename Cube in Hierarchy to SpecialCube
Drag SpecialCube into Assets
Create 2 more of these SpecialCubes from the prefab in Assets – drag from Assets into Hierarchy or Scene
![Page 17: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/17.jpg)
TestAll the cubes are identical in behavior
![Page 18: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/18.jpg)
Individualize CubesChange colors and movement vectors (X only) in the Inspector
Bold means values are set to different parameters than the initial prefab
Default values set when making the prefab
![Page 19: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/19.jpg)
TestThe cubes should behave differently
![Page 20: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/20.jpg)
Ball Rolling Tower Destroyer
Create a New 3D Project
Create:Terrain
Cube, add RigidBody componentSphere, add RigidBody component
![Page 21: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/21.jpg)
Ball Rolling Tower Destroyer
Make sure cube and sphere are above terrain
Cube and sphere Ys should be set to .5 or higher
Use ‘W’ to show translation arrows
![Page 22: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/22.jpg)
Ball Rolling Tower Destroyer
Add new script BallMover to sphere
http://pastebin.com/YpnvHxS2
![Page 23: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/23.jpg)
Ball Rolling Tower Destroyer
Add SmoothFollow script from Imported Characters Assets – search in “Add Component”
Add as component to Camera, then assign follow target as sphere
![Page 24: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/24.jpg)
TestRoll ball around and knock the cube
![Page 25: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/25.jpg)
Duplicate cubeMake 5 levels of 3x3 using CTRL+D (duplicate) and holding CTRL when repositioning (snap 1 unit of distance)
![Page 26: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/26.jpg)
TestTry destroying the tower… probably much harder to do
![Page 27: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/27.jpg)
Adjust Mass of SphereIn RigidBody component to 10
![Page 28: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/28.jpg)
TestSphere moves slower, since it is heavier, but is more effective
![Page 29: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/29.jpg)
Adjust Mass of CubesGroup select all cubes (using CTRL or CMD)
Change mass to .15
![Page 30: GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®](https://reader036.fdocuments.in/reader036/viewer/2022062407/56649d345503460f94a0b7a5/html5/thumbnails/30.jpg)
TestKnock over everything!