Zatím nedodělané

This commit is contained in:
Haitem
2020-07-13 21:48:15 +02:00
parent 90361a6dff
commit cb44205ec9
21 changed files with 1993 additions and 1036 deletions

View File

@@ -1,8 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class BlockManager : MonoBehaviour
public class BlockManager : NetworkBehaviour
{
public enum BlockType {None, Barricade, Door, Wood, Ammo, FireCamp, Pills};
public BlockType blockType = BlockType.None;

View File

@@ -2,8 +2,9 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Networking;
public class EnemyManager : MonoBehaviour
public class EnemyManager : NetworkBehaviour
{
public float health = 100;
public float damage = 10;
@@ -32,6 +33,10 @@ public class EnemyManager : MonoBehaviour
// Update is called once per frame
void Update()
{
if (!isServer)
{
return;
}
DropBodyPart();
if (actualHealth <= 0)
{
@@ -59,6 +64,10 @@ public class EnemyManager : MonoBehaviour
void FixedUpdate()
{
if (!isServer)
{
return;
}
if (actualHealth > 0 && barricadeManager == null)
{
Vector3 _dir = player.transform.position - transform.position;

View File

@@ -2,8 +2,9 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
public class GuiManager : MonoBehaviour
public class GuiManager : NetworkBehaviour
{
public GameObject InteractIcon;
public Text Wood;

View File

@@ -1,8 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class MusicManager : MonoBehaviour
public class MusicManager : NetworkBehaviour
{
public AudioSource musicSource;
public AudioClip DayMusic;
@@ -13,12 +14,20 @@ public class MusicManager : MonoBehaviour
// Start is called before the first frame update
void Start()
{
if (!isLocalPlayer)
{
return;
}
musicSource.PlayOneShot(DayMusic);
}
// Update is called once per frame
void Update()
{
if (!isLocalPlayer)
{
return;
}
float sunRotationX = Sun.transform.localEulerAngles.x;
sunRotationX = (sunRotationX > 180) ? sunRotationX - 360 : sunRotationX;

View File

@@ -1,9 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
public class PlayerManager : MonoBehaviour
public class PlayerManager : NetworkBehaviour
{
public float speed = 8;
@@ -20,6 +21,7 @@ public class PlayerManager : MonoBehaviour
public int barricadeMaterials = 50;
public int ammo = 50;
public List<GameObject> weaponList = new List<GameObject>();
public GameObject player;
private GameObject createWeapon;
public GameObject spikes;
public Sprite spikesImage;
@@ -42,6 +44,14 @@ public class PlayerManager : MonoBehaviour
buildTime = buildRate;
playerCamera = GetComponentInChildren<Camera>();
rigidBody = GetComponent<Rigidbody>();
if (isLocalPlayer)
{
player.SetActive(false);
}
else
{
GetComponentInChildren<Camera>().enabled = false;
}
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
@@ -49,6 +59,10 @@ public class PlayerManager : MonoBehaviour
// Update is called once per frame
void Update()
{
if (!isLocalPlayer)
{
return;
}
if (Input.GetKeyDown(KeyCode.Escape))
{
Application.Quit(0);
@@ -59,7 +73,7 @@ public class PlayerManager : MonoBehaviour
RunSwitch();
SelectWeapon();
Interact();
if (actualHealth <= 0)
{
if (audio != null && lose != null && (nextMapeTime2 + 1) <= Time.time)
@@ -73,7 +87,8 @@ public class PlayerManager : MonoBehaviour
audio.PlayOneShot(lose);
nextMapeTime2 = nextMapeTime + Time.time;
}
if (nextMapeTime2 <= Time.time) {
if (nextMapeTime2 <= Time.time)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);
}
}
@@ -84,6 +99,10 @@ public class PlayerManager : MonoBehaviour
void FixedUpdate()
{
if (!isLocalPlayer)
{
return;
}
Rotate();
}
@@ -153,12 +172,12 @@ public class PlayerManager : MonoBehaviour
WeaponManager weaponManager = weaponList[selectedWeapon].GetComponent<WeaponManager>();
if (weaponManager != null) {
weaponManager.player = this;
Debug.Log(weaponList.Count);
if (Input.GetAxis("Mouse ScrollWheel") > 0 && selectTime < Time.time)
{
if (weaponManager != null && createWeapon != null)
{
Destroy(createWeapon);
Destroy(this.createWeapon);
CmdDestroyWeapon(createWeapon);
}
}
else if (Input.GetAxis("Mouse ScrollWheel") < 0 && selectTime < Time.time)
@@ -166,15 +185,17 @@ public class PlayerManager : MonoBehaviour
if (weaponManager != null && createWeapon != null)
{
Destroy(createWeapon);
CmdDestroyWeapon(createWeapon);
}
}
weaponManager.player = this;
if (weaponManager != null && createWeapon == null)
{
createWeapon = Instantiate(weaponList[selectedWeapon]) as GameObject;
createWeapon.transform.parent = playerCamera.transform;
createWeapon.transform.localPosition = Vector3.zero;
createWeapon.transform.localEulerAngles = Vector3.zero;
this.createWeapon = Instantiate(weaponList[selectedWeapon]) as GameObject;
this.createWeapon.transform.parent = this.playerCamera.transform;
this.createWeapon.transform.localPosition = Vector3.zero;
this.createWeapon.transform.localEulerAngles = Vector3.zero;
CmdSpawnWeapon(createWeapon);
}
}
if (Input.GetAxis("Mouse ScrollWheel") > 0 && selectTime < Time.time)
@@ -204,6 +225,18 @@ public class PlayerManager : MonoBehaviour
}
}
[Command]
void CmdSpawnWeapon(GameObject createWeapon2)
{
NetworkServer.Spawn(createWeapon2);
}
[Command]
void CmdDestroyWeapon(GameObject createWeapon2)
{
NetworkServer.Destroy(createWeapon2);
}
void Interact()
{
Ray ray = playerCamera.ScreenPointToRay(Input.mousePosition);