Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning C# by Developing Games with Unity 2019

You're reading from   Learning C# by Developing Games with Unity 2019 Code in C# and build 3D games with Unity

Arrow left icon
Product type Paperback
Published in Mar 2019
Publisher Packt
ISBN-13 9781789532050
Length 342 pages
Edition 4th Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Harrison Ferrone Harrison Ferrone
Author Profile Icon Harrison Ferrone
Harrison Ferrone
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. Section 1: Programming Foundations and C# FREE CHAPTER
2. Getting to Know your Environment 3. The Building Blocks of Programming 4. Diving into Variables,Types, and Methods 5. Control Flow and Collection Types 6. Working with Classes, Structs, and OOP 7. Section 2: Scripting Game Mechanics in Unity
8. Getting Your Hands Dirty with Unity 9. Movement, Camera Controls, and Collisions 10. Scripting Game Mechanics 11. Basic AI and Enemy Behavior 12. Section 3: Leveling Up Your C# Code
13. Revisiting Types, Methods, and Classes 14. Exploring Generics, Delegates, and Beyond 15. The Journey Continues 16. Completed Game Files 17. Supplementary Classes 18. Pop Quiz Answers 19. Other Books You May Enjoy

Player behavior

This is attached to the Player object—it requires a Rigidbody and CapsuleCollider component, as follows:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerBehavior : MonoBehaviour
{
public float moveSpeed = 10f;
public float rotateSpeed = 75f;
public float jumpVelocity = 5f;
public float distanceToGround = 0.1f;
public LayerMask groundLayer;
public GameObject bullet;
public float bulletSpeed = 100f;

public delegate void JumpingEvent(bool isGrounded);
public event JumpingEvent playerJump;

private float _vInput;
private float _hInput;
private Rigidbody _rb;
private CapsuleCollider _col;
private GameBehavior _gameManager;

void Start()
{
_rb = GetComponent<Rigidbody>();
_col = GetComponent<CapsuleCollider>();
_gameManager = GameObject.Find("Game Manager").GetComponent<GameBehavior>();
}

void Update()
...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image