Presentation is loading. Please wait.

Presentation is loading. Please wait.

GameCamp! and Game Davis Introduction to Scripting in Unity®

Similar presentations


Presentation on theme: "GameCamp! and Game Davis Introduction to Scripting in Unity®"— Presentation transcript:

1 GameCamp! and Game Dev @ Davis Introduction to Scripting in Unity®

2 Create Standard 3D Project

3 Unity® Interface

4 Create Cube ▼Create ►3D Object ►Cube

5 Add a Script Component Name: ColorChanger public Color color; Void Start { GetComponent ().material.color = color; }

6 Test See that while the cube is white in the scene view, when the game runs, the cube changes to the assigned color

7 Add Another Script Component Name: Mover public Vector3 movementVector = Vector3.right; Void Update { transform.position += movementVector * Time.deltaTime; }

8 Test Notice that the cube only moves to the right indefinitely

9 Add More Code to Mover private Vector3 startPosition; Void Start { startPosition = transform.position; }

10 Add More Code to Mover After 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;

11 Test Now the cube should move back and forth when the game is run

12 Make the Scripts Interact Make changes to ColorChanger public Color color1; public Color color2;

13 Make the Scripts Interact Revise the Start code: Delete: GetComponent ().material.color = color;

14 Make the Scripts Interact void Update () { if (GetComponent ().movementVector == Vector3.left) GetComponent ().material.color = color1; else Getcomponent ().material.color = color2; }

15 Test The cube should move back and forth and also change colors when changing directions

16 Create Prefab Rename 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

17 Test All the cubes are identical in behavior

18 Individualize Cubes Change 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

19 Test The cubes should behave differently

20 Ball Rolling Tower Destroyer Create a New 3D Project Create: Terrain Cube, add RigidBody component Sphere, add RigidBody component

21 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

22 Ball Rolling Tower Destroyer Add new script BallMover to sphere http://pastebin.com/YpnvHxS2

23 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

24 Test Roll ball around and knock the cube

25 Duplicate cube Make 5 levels of 3x3 using CTRL+D (duplicate) and holding CTRL when repositioning (snap 1 unit of distance)

26 Test Try destroying the tower… probably much harder to do

27 Adjust Mass of Sphere In RigidBody component to 10

28 Test Sphere moves slower, since it is heavier, but is more effective

29 Adjust Mass of Cubes Group select all cubes (using CTRL or CMD) Change mass to.15

30 Test Knock over everything!


Download ppt "GameCamp! and Game Davis Introduction to Scripting in Unity®"

Similar presentations


Ads by Google