Presentation is loading. Please wait.

Presentation is loading. Please wait.

Expandable Item Classes ch 3

Similar presentations


Presentation on theme: "Expandable Item Classes ch 3"— Presentation transcript:

1 Expandable Item Classes ch 3
Richard Gesick

2 Objectives Creating customizable classes for items
Learning how GameObjects can interact with each other through sending messages Creating a Projectile item class Utilizing a classification system for all objects to decide what they do Using trigger-based collisions for the Melee and Projectile item classes Using two types of movement for projectile items

3 Projectiles The first example:
GameObject instantiatedProjectile = Instantiate(bullet, new Vector3(transform.position.x, transform.position.y + 1, transform.position.z + 1), transform.rotation) as GameObject; Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

4 Projectiles GameObject instantiatedProjectile = Instantiate(shot, shotSpawn.position, shotSpawn.rotation) as GameObject; Destroy(instantiatedProjectile, 5f); Or GameObject go = GameObject.Find("shotspawn"); GameObject instantiatedProjectile = Instantiate(bullet, go.transform.position, go.transform.rotation) as GameObject;

5 KeyValuePair C# struct KeyValuePair<Tkey, Tval>
foreach( KeyValuePair<string, string> kvp in openWith ) { Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); }

6 More KeyValuePair Uses parallel lists which is not normally a good idea but is probably the easiest way to handle this List<KeyValuePair<int, string>> items = new List<KeyValuePair<int, string>>(); List<KeyValuePair<int, int>> itemCount = new List<KeyValuePair<int, int>>(); . . . items.Add(new KeyValuePair<int, string>(i, invItems[i])); itemCount.Add(new KeyValuePair<int, int>(i, 0)); Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

7 Sending Messages From a destroy by contact method void OnTriggerEnter(Collider col) { if (col.gameObject.name == "Eathan") col.gameObject.SendMessage("changeHealth", 10); Destroy(this.gameObject); } . . . Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

8 Triggers and actions void OnTriggerEnter(Collider col) {
switch(col.gameObject.tag) case "Enemy": if(meleeType != MeleeType.Potion) break; case "Environment": if(meleeType == MeleeType.Potion) break; } Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

9 Different movements public MovementType moveType = MovementType.None; // reassigned in the inspector void Update() { switch(moveType) case MovementType.Basic: BasicMovement(); break; case MovementType.Drop: DropMovement(); break; } Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


Download ppt "Expandable Item Classes ch 3"

Similar presentations


Ads by Google