Large diffs are not rendered by default.

@@ -2,16 +2,21 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;

public class CharacterMovement : NetworkBehaviour {
public float m_speed = 5.0f;
public float m_speedMultiplier = 1.0f;
public float m_gravity = 20.0f;
public SoundMGR m_soundManager;
public bool m_hasClicked = false;
public float m_jumpSpeed = 8.0f;
public MeshCollider m_swordCollider;
public int m_numOfBlockedAttacks = 0;
public bool m_cantTakeDamage = false;
public GameObject m_camtarget;
public bool m_isDead = false;

private Vector3 m_moveDirection = Vector3.zero;
private bool m_isJumping;
private bool m_isGrounded = false;
@@ -21,7 +26,6 @@ public class CharacterMovement : NetworkBehaviour {
private bool m_isAttacking;
public Health m_healthScript;
private bool m_disableMovement;
public SoundMGR m_soundManager;

// Use this for initialization
void Start() {
@@ -33,55 +37,57 @@ public class CharacterMovement : NetworkBehaviour {

// Update is called once per frame
void Update () {
if(!m_disableMovement) {
m_moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
if(GameManager.Instance.m_gameStarted) {
if(!m_disableMovement) {
m_moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

if(Input.GetButtonDown("Jump") && m_isGrounded) {
m_moveDirection.y = m_jumpSpeed;
m_isJumping = true;
}
if(Input.GetButtonDown("Jump") && m_isGrounded) {
m_moveDirection.y = m_jumpSpeed;
m_isJumping = true;
}

m_moveDirection *= m_speed * m_speedMultiplier;
m_moveDirection *= m_speed * m_speedMultiplier;

m_animController.SetFloat("Forward", m_moveDirection.z);
m_animController.SetFloat("Right", m_moveDirection.x);
m_animController.SetFloat("Forward", m_moveDirection.z);
m_animController.SetFloat("Right", m_moveDirection.x);

m_moveDirection = transform.TransformDirection(m_moveDirection);

m_moveDirection = transform.TransformDirection(m_moveDirection);

m_moveDirection.y -= m_gravity * Time.deltaTime;
m_isGrounded = ((m_controller.Move(m_moveDirection * Time.deltaTime)) & CollisionFlags.Below) != 0;
m_moveDirection.y -= m_gravity * Time.deltaTime;
m_isGrounded = ((m_controller.Move(m_moveDirection * Time.deltaTime)) & CollisionFlags.Below) != 0;


if(Input.GetMouseButtonDown(0) && m_isAttacking == false) {
m_swordCollider.enabled = true;
m_animController.SetBool("isAttacking", true);
m_isAttacking = true;
Debug.Log(m_animController.GetBool("isAttacking"));
if(Input.GetMouseButtonDown(0) && m_isAttacking == false) {
m_swordCollider.enabled = true;
m_animController.SetBool("isAttacking", true);
m_isAttacking = true;
Debug.Log(m_animController.GetBool("isAttacking"));
}
}
}

if(Input.GetMouseButtonDown(1) && m_numOfBlockedAttacks <= 3) {
m_disableMovement = true;
m_animController.SetBool("isBlocking", true);
m_cantTakeDamage = true;
Debug.Log("Cant tank damage should be true: " + m_cantTakeDamage);
}
if(Input.GetMouseButtonDown(1) && m_numOfBlockedAttacks <= 3) {
m_disableMovement = true;
m_animController.SetBool("isBlocking", true);
m_cantTakeDamage = true;
Debug.Log("Cant tank damage should be true: " + m_cantTakeDamage);
}

if(Input.GetMouseButtonUp(1)) {
m_disableMovement = false;
m_animController.SetBool("isBlocking", false);
m_cantTakeDamage = false;
}
if(Input.GetMouseButtonUp(1)) {
m_disableMovement = false;
m_animController.SetBool("isBlocking", false);
m_cantTakeDamage = false;
}

if(Input.GetKeyDown(KeyCode.R)) {
CmdTakeDamage(10);
if(Input.GetKeyDown(KeyCode.R)) {
m_healthScript.TakeDamage(10);
}
}
}

public void CmdTakeDamage(int damage) {
m_healthScript.TakeDamage(damage);
m_healthScript.UpdateHealth();
//m_healthScript.UpdateHealth();
}

void BlockedAttack() {
@@ -96,5 +102,13 @@ public class CharacterMovement : NetworkBehaviour {
m_swordColliderScript.m_hasDealtDamage = false;
m_isAttacking = false;
}

public void GameOver() {
if(m_isDead) {
SceneManager.LoadScene("Lose");
} else {
SceneManager.LoadScene("Win");
}
}
}

@@ -28,7 +28,7 @@ public class GameManager : MonoBehaviour {
}

private void Awake() {
DontDestroyOnLoad(transform.gameObject);
//DontDestroyOnLoad(transform.gameObject);
m_instance = this;
m_gameStartingIn.text = m_numReadyPlayers + "/2";
}
@@ -50,7 +50,7 @@ public class GameManager : MonoBehaviour {
m_numPlayersActive--;
if(m_numPlayersActive <= 1) {
for(int i = 0; i < m_players.Count; i++) {
//m_players[i].GetComponent<CharacterMovement>().GameOver();
m_players[i].GetComponent<CharacterMovement>().GameOver();
}
}
}
@@ -10,8 +10,11 @@ public class Health : NetworkBehaviour {
[SyncVar(hook = "UpdateHealth")]
public int m_currHealth;

private CharacterMovement m_playerScript;

void Start() {
m_currHealth = m_maxHealth;
m_playerScript = GetComponent<CharacterMovement>();
}

public void TakeDamage(int damage) {
@@ -26,7 +29,10 @@ public class Health : NetworkBehaviour {
}

void Dead() {
Destroy(this.gameObject);
GameManager.Instance.m_gameStarted = false;
this.gameObject.SetActive(false);
m_playerScript.m_isDead = true;
GameManager.Instance.CheckGameOver();
}

public int GetCurrentHealth() {
@@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class WinLoseManager : MonoBehaviour {

public void QuitGame() {
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}

public void PlayAgain() {
SceneManager.LoadScene("MainMenuScene");
// TODO: maybe make reset function to reset all gamemanager variables
}
}
@@ -5,12 +5,18 @@ EditorBuildSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Scenes:
- enabled: 0
path:
guid: 00000000000000000000000000000000
- enabled: 1
path: Assets/Scenes/Menu.unity
guid: 6ac5e16b081f3dd4399f82faab421e49
- enabled: 1
path: Assets/Scenes/GameplayMain.unity
guid: 82072fc5c299331409c2c10b9b8397a4
- enabled: 1
path: Assets/Scenes/MainMenuScene.unity
guid: a0277e73ef743ae4bb9dda6a4073796c
- enabled: 1
path: Assets/Scenes/Win.unity
guid: b1a75abe04a23284f9bd9b59b7e9e8b5
- enabled: 1
path: Assets/Scenes/Lose.unity
guid: eeb6f67120dd4cf4ba17fc8bfc32fecc