Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Game Development using Unity3D

0e85b7c8ba425d53570b1fbfadb5436a?s=47 Joshua de Guzman
August 24, 2018
220

Game Development using Unity3D

This presentation was used during my seminar / workshop with the topic "Game Development using Unity3D".

Write up available on: https://blog.jmdg.io/unity3d-introduction

Attributions:
Slide #2:
Featured Unity Games (International)
https://unity3d.com/games-made-with-unity

Slide #3:
Showcasing locally made games (Philippines)
http://xupergames.com/

0e85b7c8ba425d53570b1fbfadb5436a?s=128

Joshua de Guzman

August 24, 2018
Tweet

Transcript

  1. Game Development with Unity3D @joshuadeguzman

  2. None
  3. None
  4. Agenda • Game Development with Unity3D • FPS Game Development

    • VR & AR Workshop • Mobile Optimization • Game Deployment
  5. Unity3D

  6. Unity3D Unity3D is game development tool or game engine used

    by most of the developers in creating great game applications for desktop, mobile and web.
  7. Scene

  8. Asset Packages

  9. Standard Assets

  10. Unity Packages

  11. Prefab Prefabricated object

  12. GameObject

  13. Component

  14. Scripting Anatomy of a Script File using UnityEngine; public class

    Weapon : MonoBehaviour { private void Start() { private void Update() { } }
  15. Scripting using UnityEngine; public class Weapon : MonoBehaviour private AudioSource

    weaponAudioSource; { private void Start() { weaponAudioSource = GetComponent<AudioSource>(); } private void Update() { } }
  16. Assets

  17. FPS Game Development

  18. FPS By the end of this tutorial, you are expected

    to: • Import Packages • Create a scene • Setup FPS camera • Develop FPS character from scratch • Implement basic weapon functionalities • Attach FPS weapons to your character • Add custom animations to weapons and environment
  19. public Rigidbody rbPlayer; private void Start() { rbPlayer = GetComponent<Rigidbody>();

    } FPS PlayerController.cs
  20. public Rigidbody rbPlayer; public float walkSpeed = 3f; private void

    Move() { var moveDirection = new Vector3( Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")); moveDirection = Camera.main.transform.TransformDirection(moveDirection); moveDirection.y = 0; rbPlayer.MovePosition(rbPlayer.position + moveDirection * walkSpeed * Time.deltaTime); } FPS PlayerController.cs
  21. private void FixedUpdate() { Move(); } FPS PlayerController.cs

  22. public Rigidbody rbPlayer; public Vector3 jump; private void Start() {

    rbPlayer = GetComponent<Rigidbody>(); jump = new Vector3(0f, jumpForce, 0f); } FPS PlayerController.cs
  23. public Vector3 jump; public bool isJumping; public float jumpForce =

    2.0f; public bool isGrounded; private void Jump() { if (isJumping) { isJumping = !isJumping; isGrounded = false; rbPlayer.AddForce(jump * jumpForce, ForceMode.Impulse); } } FPS PlayerController.cs
  24. private void FixedUpdate() { Move(); Jump(); } FPS PlayerController.cs

  25. private void Update() { CallDefaultBehavior(); if (Input.GetKeyDown(KeyCode.Space) && isGrounded) {

    isJumping = true; } } private void CallDefaultBehavior() { isJumping = false; } FPS PlayerController.cs
  26. public Rigidbody rbPlayer ; public bool isRunning ; public float

    runSpeed = 10f; private void Move() { var moveDirection = new Vector3(Input.GetAxisRaw ("Horizontal "), 0, Input.GetAxisRaw ("Vertical ")); moveDirection = Camera.main.transform .TransformDirection (moveDirection ); moveDirection .y = 0; if (isRunning ) { rbPlayer .MovePosition (rbPlayer .position + moveDirection * runSpeed * Time.deltaTime ); } else { rbPlayer .MovePosition (rbPlayer .position + moveDirection * walkSpeed * Time.deltaTime ); } } FPS PlayerController.cs
  27. private void Update() { CallDefaultBehavior(); if (Input.GetKeyDown(KeyCode.Space) && isGrounded) {

    isJumping = true; } if (Input.GetKey(KeyCode.LeftShift)) { isRunning = true; } } FPS PlayerController.cs
  28. FPS PlayerController.cs private void CallDefaultBehavior() { isJumping = false; isRunning

    = false; }
  29. FPS FPSMouseScript.cs public enum RotationAxes { MouseXAndY = 0, MouseX

    = 1, MouseY = 2 } public RotationAxes axes = RotationAxes.MouseXAndY; public float sensitivityX = 15F; public float sensitivityY = 15F; public float minimumX = -360F; public float maximumX = 360F; public float minimumY = -60F; public float maximumY = 60F; float rotationY = 0F;
  30. void Start() { // Make the rigid body not change

    rotation if (GetComponent<Rigidbody>()) GetComponent<Rigidbody>().freezeRotation = true; } FPS FPSMouseScript.cs
  31. void Update() { if (axes == RotationAxes.MouseXAndY) { float rotationX

    = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX; rotationY += Input.GetAxis("Mouse Y") * sensitivityY; rotationY = Mathf.Clamp(rotationY, minimumY, maximumY); transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0); } } FPS FPSMouseScript.cs
  32. void Update() { ... else if (axes == RotationAxes.MouseX) {

    transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0); } } FPS FPSMouseScript.cs
  33. void Update() { ... else { rotationY += Input.GetAxis("Mouse Y")

    * sensitivityY; rotationY = Mathf.Clamp(rotationY, minimumY, maximumY); transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0); } } FPS FPSMouseScript.cs
  34. FPS WeaponController.cs public float damageAmount = 100f; public float range

    = 100f; public Camera playerCamera; private void Update() { if (Input.GetButton("Fire1") && Time.time >= nextFire) { Shoot(); } }
  35. public Camera playerCamera; private void Shoot() { RaycastHit hit; if

    (Physics.Raycast( playerCamera.transform.position, playerCamera.transform.forward, out hit, range)) { Debug.Log(hit.transform.name) } } FPS WeaponController.cs
  36. public float health = 100f; public GameObject gameObjectDestroy ; public

    void TakeDamage (float damageAmount ) { Debug .Log("Target Health: " + health); health -= damageAmount ; if (health <= 0f) { Die(); } } public void Die() { gameObjectDestroy .SetActive (true); Destroy(gameObject ); } FPS Target.cs
  37. public Camera playerCamera; private void Shoot() { RaycastHit hit; if

    (Physics.Raycast( playerCamera.transform.position, playerCamera.transform.forward, out hit, range)) { Target target = hit.transform.GetComponent<Target>(); if (target != null) { target.TakeDamage(damageAmount); } } } FPS WeaponController.cs
  38. public Camera playerCamera ; public float hitForce = 60f; private

    void Shoot() { RaycastHit hit; if (Physics.Raycast( playerCamera .transform .position , playerCamera .transform .forward, out hit, range)) { ... // Slightly move the object when being hit by the weapon if (hit.rigidbody != null) { hit.rigidbody .AddForce (-hit.normal * hitForce ); } } } FPS WeaponController.cs
  39. public Camera playerCamera ; public ParticleSystem impactWood ; private void

    Shoot() { ... { ParticleSystem impactEffect = impactDefault ; if (hit.transform .gameObject .tag != "" || hit.transform .gameObject .tag != "Untagged ") { switch (hit.transform .gameObject .tag) { case "Wood": impactEffect = impactWood ; Break; ... } } } FPS WeaponController.cs
  40. public Camera playerCamera ; public float hitForce = 60f; private

    void Shoot() { ... { ParticleSystem impactEffect = impactDefault ; ... // Render impact effect GameObject hitObject = Instantiate ( impactEffect , hit.point, Quaternion .LookRotation (hit.normal)).gameObject ; Destroy(hitObject , 2f); } } FPS WeaponController.cs
  41. public AudioClip soundFireShot; private AudioSource weaponAudioSource; private float lowPitchRange =

    .75F; private float highPitchRange = 1.5F; private void Start() { muzzleFlash.Stop(); } private void Shoot() { muzzleFlash.Play(); ... } FPS WeaponController.cs
  42. public AudioClip soundFireShot; private AudioSource weaponAudioSource; private float lowPitchRange =

    .75F; private float highPitchRange = 1.5F; private void Start() { muzzleFlash.Stop(); weaponAudioSource = GetComponent<AudioSource>(); } private void PlayFireSound() { weaponAudioSource.pitch = Random.Range(lowPitchRange, highPitchRange); weaponAudioSource.PlayOneShot(soundFireShot); } FPS WeaponController.cs
  43. public float fireRate = 10f; public float nextFire = 0f;

    private void Update() { if (Input.GetButton("Fire1") && Time.time >= nextFire) { nextFire = Time.time + 1f / fireRate; PlayFireSound(); Shoot(); } } FPS WeaponController.cs
  44. VR & AR Workshop

  45. Mobile Optimization

  46. Mobile Optimization • Profiling your Game ◦ Test your game

    on different devices • Scripts ◦ Use Coroutines instead of Update() ◦ Reactive Programming ◦ Event Based Call • Lighting ◦ Baked ◦ Light Probes ◦ Shadows ◦ Quality Settings
  47. Mobile Optimization • Shades, Textures & UI Optimization • Audio

    Optimizations • Keep your assets’ triangles, vertices and drawcalls as low as possible
  48. Mobile Optimization • Shades, Textures & UI Optimization ◦ Keep

    your assets’ triangles, vertices and draw calls as low as possible • Audio Optimizations ◦ Shorter - Native ◦ Longer - compressed in memory ◦ Files with continuous CPU spikes - decompress on load • Optimizing garbage collection ◦ Handling Memory Management
  49. Game Deployment

  50. Game Deployment

  51. Happy Coding! Thanks!