mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 20:52:10 +01:00
Merge branch 'main' into weapons-without-scriptableobjects
This commit is contained in:
@@ -7,7 +7,13 @@ public class Player : NetworkBehaviour
|
||||
{
|
||||
public bool isAlive = true;
|
||||
public Team team;
|
||||
|
||||
|
||||
|
||||
[SerializeField]PlayerUIController playerUIController;
|
||||
[SerializeField] private const int defaultHp = 100;
|
||||
GameObject GameManager;
|
||||
GameMaster gameMaster;
|
||||
|
||||
|
||||
public ulong clientId;
|
||||
@@ -23,9 +29,28 @@ public class Player : NetworkBehaviour
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
||||
GameManager = GameObject.Find("MatchController");
|
||||
gameMaster = GameManager.GetComponent<GameMaster>();
|
||||
if (isServer)
|
||||
{
|
||||
health = defaultHp;
|
||||
gameMaster.RegisterPlayer(GetComponent<Player>());
|
||||
//respawnPos(gameMaster.RespawnRequest(this.gameObject, team.teamID));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.N))
|
||||
{
|
||||
playerUIController.showHit();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
public override void OnStartLocalPlayer()
|
||||
@@ -46,6 +71,23 @@ public class Player : NetworkBehaviour
|
||||
}
|
||||
public void Respawn()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
[Command]
|
||||
void CmdRespawnRequest()
|
||||
{
|
||||
respawnPos(gameMaster.RespawnRequest(this.gameObject, team.teamID));
|
||||
isAlive = true;
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
public void respawnPos(Vector3 pos)
|
||||
{
|
||||
GetComponent<CharacterController>().enabled = false;
|
||||
transform.position = pos;
|
||||
GetComponent<CharacterController>().enabled = true;
|
||||
health = defaultHp;
|
||||
isAlive = true;
|
||||
}
|
||||
|
||||
@@ -53,6 +95,7 @@ public class Player : NetworkBehaviour
|
||||
{
|
||||
isAlive = false;
|
||||
AddDeaths(1);
|
||||
Debug.Log("DIE");
|
||||
}
|
||||
|
||||
//Health
|
||||
@@ -70,17 +113,22 @@ public class Player : NetworkBehaviour
|
||||
|
||||
if (isAlive)
|
||||
{
|
||||
/*Debug.Log("yeet" + value);*/
|
||||
ShowHit();
|
||||
health -= value;
|
||||
if (health <= 0)
|
||||
{
|
||||
AddDeaths(1);
|
||||
health = 0;
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
private void ShowHit()
|
||||
{
|
||||
playerUIController.showHit();
|
||||
}
|
||||
public void SetHealth(int value)
|
||||
{
|
||||
if (isAlive)
|
||||
@@ -139,3 +187,7 @@ public class Player : NetworkBehaviour
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -54,7 +55,6 @@ public class PlayerController : NetworkBehaviour
|
||||
Grounded();
|
||||
CheckGoundAngle();
|
||||
UpdateMovement();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -97,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()
|
||||
{
|
||||
|
||||
@@ -116,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)
|
||||
{
|
||||
@@ -151,6 +162,7 @@ public class PlayerController : NetworkBehaviour
|
||||
|
||||
velocity = Vector3.SmoothDamp(velocity, currentDir * movementSpeed + new Vector3(0, velocityY, 0),ref refVelocity,0.01f);
|
||||
controller.Move(velocity * Time.deltaTime);
|
||||
//transform.position += velocity * Time.deltaTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
8
Assets/Scripts/Player/UI Player.meta
Normal file
8
Assets/Scripts/Player/UI Player.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0a3c5a29b2b3314a845a2041778a5e7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
62
Assets/Scripts/Player/UI Player/PlayerUIController.cs
Normal file
62
Assets/Scripts/Player/UI Player/PlayerUIController.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Player/UI Player/PlayerUIController.cs.meta
Normal file
11
Assets/Scripts/Player/UI Player/PlayerUIController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 39474c96d3f51c84688c71e41ec03d7b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user