Lecture 3 Richard Gesick

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 18 Indexing Structures for Files.
Advertisements

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Part 1 Conditionals and Loops.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 11.9 Curvature and Normal Vectors.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 11.5 Lines and Curves in Space.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1 Functions.
Copyright © 2011 Pearson Education, Inc. Publishing as Longman.
Copyright © 2007 Pearson Education, Inc., publishing as Pearson Addison Wesley.
Transcendental Functions
Functions of Several Variables
Chapter 1 Functions Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Chapter 3 Derivatives Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
© 2015 Pearson Education, Inc.
Expandable Item Classes ch 3
5.5 Solving Exponential and Logarithmic Equations
Chapter 3 Differentiation
© 2010 Pearson Education, Inc. All rights reserved
Chapter 9 Power Series Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Chapter 2 Limits Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
© 2010 Pearson Education, Inc. All rights reserved
© 2015 Pearson Education, Inc.
Sequences and Infinite Series
Copyright © 2005 Pearson Education, Inc
Integration Techniques
Inventory ch 4 Richard Gesick.
Chapter 17 Linked Lists.
Chapter 19 Binary Search Trees.
11.7 Motion in Space Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Chapter 4 Inheritance.
Further Applications of Integration
© 2010 Pearson Education, Inc. All rights reserved
Chapter 14 Graphs and Paths.
Chapter 3 Integration Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Copyright © 2006 Pearson Education, Inc
Chapter 10 Datapath Subsystems.
Applications of the Derivative
Chapter 5 Integration Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
11.8 Length of Curves Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Chapter 20 Hash Tables.
Chapter 2 Limits and Continuity
Mathematical Models: Building Functions
Copyright © 2011 Pearson Education, Inc
Applications of Definite Integrals
Chapter 1 Preliminaries
Copyright © 2006 Pearson Education, Inc
Searching for Guinea Pig B: Case Study in Online Research
2.2 The Algebra of Functions
Chapter 1 Functions Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Chapter 15 Multiple Integrals
Chapter 5 Algorithm Analysis.
Copyright © 2006 Pearson Education, Inc
Vector-Valued Functions and Motion in Space
Fundaments of Game Design
The Facts to Be Explained
Copyright © 2006 Pearson Education, Inc
Fundaments of Game Design
Alternate Proofs of Selected HO Theorems
Conic Sections and Polar Coordinates
Chemistry Ch. 10 Review and worksheets
Introduction: Some Representative Problems
2.3 The Composition of Functions
Circuit Characterization and Performance Estimation
Copyright © 2006 Pearson Education, Inc
The Classical Model with Many Goods
Chapter 2 Part 1 Data and Expressions.
Chapter 6 Dynamic Programming.
Chapter 2 Reference Types.
Chapter 4 Greedy Algorithms.
Copyright © 2011 Pearson Education, Inc
Chapter 5 Integration Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Presentation transcript:

Lecture 3 Richard Gesick GUI Ch 2 Lecture 3 Richard Gesick

objectives Both 2D and 3D GUI elements How to create GUI buttons How to create a 2D health bar Tracking the player's level by using a GUI label Using two GUI boxes to make an experience bar Creating a 3D health bar Showing 3D damage reports Showing enemy name tags

2D List<Rect> SkillButtons = new List<Rect>(); List<Rect> ItemButtons = new List<Rect>(); SkillButtons.Add(new Rect(Screen.width/2 + 50, Screen.height/2 + 333, 55, 55)); SkillButtons.Add(new Rect(Screen.width/2 + 105, Screen.height/2 + 333, 55, 55)); ItemButtons.Add(new Rect(Screen.width/2 - 160, Screen.height/2 + 333, 55, 55)); Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

OnGUI() method GUI.Button(SkillButtons[0], "Skill A"); GUI.Button(SkillButtons[1], "Skill B"); GUI.Button(ItemButtons[0], "Item A"); Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

A health bar with a GUI box public float currentHP = 100; public float maxHP = 100; public float currentBarLength; public float maxBarLength = 100; . . . currentBarLength = currentHP * maxBarLength / maxHP; GUI.Box(new Rect(Screen.width/2 - 20, Screen.height/2 + 300, currentBarLength, 25f), ""); Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

3D txtColor = DamageReport.color; txtColor.a = 0; // 0 transparent, 1 fully opague … HealthBar.transform.LookAt(Camera.main.transform); DamageReport.text = Damage.ToString(); txtColor.a = 1; HealthBar.transform.localScale = Vector3.Lerp(OrigScale, new Vector3(currentBarLength, OrigScale.y,OrigScale.z), Time.fixedTime); Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Assignments Rather than assign the 3D gui to the object, assign to a global object, i.e. the camera. To maintain visibility, in update use: HealthBar.transform.LookAt(Camera.main.transform); NameTag.transform.LookAt (new Vector3(-Camera.main.transform.position.x, -Camera.main.transform.position.y, -Camera.main.transform.position.z)); Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

bullets Prefab bullet GameObject instantiatedProjectile= Instantiate(bullet, new Vector3(transform.position.x, transform.position.y + 1, transform.position.z + 1), transform.rotation) as GameObject; //Or make a shot spawn position Destroy(instantiatedProjectile, 2f); Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

collisions OnTriggerEnter(Collider col) OnCollisionEnter(Collision col) Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley