Alles alter

This commit is contained in:
juliuse98
2021-11-24 12:54:43 +01:00
parent ad238ac417
commit 6bbe58799d
40 changed files with 2692 additions and 694 deletions

View File

@@ -7,6 +7,10 @@ public class Player : NetworkBehaviour
{
public bool isAlive = true;
public Team team;
[SerializeField]PlayerUIController playerUIController;
[SerializeField] private const int defaultHp = 100;
GameObject GameManager;
GameMaster gameMaster;
@@ -42,11 +46,9 @@ public class Player : NetworkBehaviour
{
if (isLocalPlayer)
{
if (Input.GetKeyDown("n"))
if (Input.GetKeyDown(KeyCode.N))
{
//Debug.Log("Request respawn on local player");
CmdRespawnRequest();
//transform.position = Vector3.zero;
playerUIController.showHit();
}
}
@@ -111,6 +113,7 @@ public class Player : NetworkBehaviour
if (isAlive)
{
ShowHit();
health -= value;
if (health <= 0)
{
@@ -120,6 +123,12 @@ public class Player : NetworkBehaviour
}
}
[ClientRpc]
private void ShowHit()
{
playerUIController.showHit();
}
public void SetHealth(int value)
{
if (isAlive)

View File

@@ -13,6 +13,7 @@ public class PlayerController : NetworkBehaviour
[SerializeField] private float walkSpeed = 6.0f;
[SerializeField] private float sprintSpeed = 10.0f;
[SerializeField] private float aimWalkSpeed = 3.0f;
[SerializeField] private float fallDamageSpeed = 10.0f;
[SerializeField][Range(0.0f, 0.5f)] private float moveSmoothTime = 0.001f;
[SerializeField] float gravity = -10.0f;
@@ -96,7 +97,11 @@ public class PlayerController : NetworkBehaviour
Gizmos.color = Color.red;
Gizmos.DrawRay(new Ray(transform.position, moveDirection * 50));
}
[Command]
void CmdFallDamage(int damage)
{
GetComponent<Player>().RemoveHealth(damage);
}
private void UpdateMovement()
{
@@ -115,6 +120,13 @@ public class PlayerController : NetworkBehaviour
}
if(isGrounded && velocity.y < -fallDamageSpeed)
{
Debug.Log(velocity.y);
Debug.Log("Fall Damage");
CmdFallDamage((int)Mathf.Abs(velocity.y));
}
//Grounded
if (velocityY < 0)
{

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b0a3c5a29b2b3314a845a2041778a5e7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,62 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Mirror;
using TMPro;
public class PlayerUIController : NetworkBehaviour
{
[SerializeField] Canvas playerUICanvas;
[SerializeField] Image damageImage;
[SerializeField] TMP_Text healthText;
float hitVal = 0;
private void Start()
{
if (isLocalPlayer)
{
playerUICanvas.enabled = true;
}
}
/*
void Start()
{
GameObject imgObject = new GameObject("testAAA");
RectTransform trans = imgObject.AddComponent<RectTransform>();
trans.transform.SetParent(playerUICanvas.transform); // setting parent
trans.localScale = Vector3.one;
trans.anchoredPosition = new Vector2(0f, 0f); // setting position, will be on center
trans.sizeDelta = new Vector2(150, 200); // custom size
Image image = imgObject.AddComponent<Image>();
Texture2D tex = Resources.Load<Texture2D>("red");
image.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
imgObject.transform.SetParent(playerUICanvas.transform);
}*/
// Update is called once per frame
void FixedUpdate()
{
hitVal = gravityValue(hitVal,0.01f,0.01f,1,0,false);
damageImage.GetComponent<CanvasRenderer>().SetAlpha(hitVal);
healthText.text = GetComponent<Player>().health.ToString();
}
public void showHit()
{
hitVal = 1;
}
float gravityValue(float curretnValue, float rateOfChangePos, float rateOfChangeNeg, float maxValue, float minValue, bool add)
{
// The currentValue will be advanced by the rateOfChangePos and reduced by the rateOfChangeNeg depending on the add boolean. But only in the specified range.
// Usage: val = gravityValue(val, 0.01f, 0.05f, 1, 0, true);
float value = curretnValue;
if (add) value += rateOfChangePos;
else value -= rateOfChangeNeg;
return Mathf.Clamp(value, minValue, maxValue);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 39474c96d3f51c84688c71e41ec03d7b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -71,17 +71,21 @@ public class Shoot : NetworkBehaviour
[Command]
// This code will be executed on the Server.
private void CmdFireBullet() {
ray = new Ray(mCamera.transform.position, mCamera.transform.forward); // Raycast from Camera
if (Physics.Raycast(ray, out crosshairHitPoint, 5000f)) { // Check if Raycast is beyond 5000
hitpos = crosshairHitPoint.point; // If hitpoint is under 5000
} else {
hitpos = mCamera.transform.position + mCamera.transform.forward * 5000;
}
_pointDirection = hitpos - muzzle.transform.position;
_lookRotation = Quaternion.LookRotation(_pointDirection);
shootAnim.rotationMod[1] = Quaternion.RotateTowards(weaponHolder.transform.rotation, _lookRotation, 1f); // Point weapon to raycast hitpoint from camera
if (weapon.AllowAction) { // If not reloading etc.
ray = new Ray(mCamera.transform.position, mCamera.transform.forward); // Raycast from Camera
if (Physics.Raycast(ray, out crosshairHitPoint, 5000f))
{ // Check if Raycast is beyond 5000
hitpos = crosshairHitPoint.point; // If hitpoint is under 5000
}
else
{
hitpos = mCamera.transform.position + mCamera.transform.forward * 5000;
}
_pointDirection = hitpos - muzzle.transform.position;
_lookRotation = Quaternion.LookRotation(_pointDirection);
shootAnim.rotationMod[1] = Quaternion.RotateTowards(weaponHolder.transform.rotation, _lookRotation, 1f); // Point weapon to raycast hitpoint from camera
if (Physics.Raycast(muzzle.transform.position, muzzle.transform.forward, out hit) && weapon.CurrentAmmunition > 0) { // Raycast from Bullet Exit Point to camera raycast
bulletHole(GameObject.CreatePrimitive(PrimitiveType.Sphere), hit); // Creates bullethole where raycast hits
if (hit.transform.gameObject.GetComponent<Player>() != null) { // If hit object is a player