mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 20:52:10 +01:00
Merge branch 'player-info'
This commit is contained in:
48
Assets/Scripts/Player/Headbob.cs
Normal file
48
Assets/Scripts/Player/Headbob.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
public class Headbob : NetworkBehaviour
|
||||
{
|
||||
[SerializeField] private float posCheckDistance = 0.01f;
|
||||
[SerializeField] private float checkDist = 0.0f;
|
||||
|
||||
[Header("Step Settings")]
|
||||
[SerializeField] private float stepAmplitude;
|
||||
[SerializeField] private float stepFrequency;
|
||||
[SerializeField] private Transform Neck;
|
||||
|
||||
private Vector3 lastPos;
|
||||
private float oldDist = 0;
|
||||
private void Start()
|
||||
{
|
||||
lastPos = this.transform.position;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
float dist = Vector3.Distance(lastPos, this.transform.position);
|
||||
|
||||
|
||||
if (dist > posCheckDistance)
|
||||
{
|
||||
checkDist += dist - oldDist;
|
||||
lastPos = this.transform.position;
|
||||
oldDist = dist;
|
||||
}
|
||||
if (checkDist > 2)
|
||||
{
|
||||
checkDist = 0;
|
||||
}
|
||||
Vector3 newPos = new Vector3(Neck.transform.position.x,getSin(stepAmplitude,stepAmplitude,checkDist),Neck.transform.position.z);
|
||||
Neck.position = newPos;
|
||||
Debug.Log("Distance: " + checkDist + ", Sin " + getSin(stepAmplitude, stepAmplitude, checkDist));
|
||||
|
||||
}
|
||||
|
||||
private float getSin(float multiplier, float devisor,float x)
|
||||
{
|
||||
return multiplier * Mathf.Sin((x/Mathf.PI)*10);
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Player/Headbob.cs.meta
Normal file
11
Assets/Scripts/Player/Headbob.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4db7caf602ce379408a59c8722e06e46
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -5,23 +5,33 @@ using Mirror;
|
||||
|
||||
public class Player : NetworkBehaviour
|
||||
{
|
||||
public bool isAlive;
|
||||
public bool isAlive = true;
|
||||
public Team team;
|
||||
[SerializeField] private const int defaultHp = 100;
|
||||
|
||||
|
||||
public ulong clientId;
|
||||
|
||||
[SyncVar(hook = nameof(SetName))]
|
||||
[SyncVar(hook = nameof(SetName))]
|
||||
public string username;
|
||||
|
||||
[SerializeField] GameObject usernameTextObj;
|
||||
|
||||
private int health;
|
||||
[SerializeField] [SyncVar]public int health = 100;
|
||||
private int kills;
|
||||
private int deaths;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (isServer)
|
||||
{
|
||||
health = defaultHp;
|
||||
}
|
||||
}
|
||||
public override void OnStartLocalPlayer()
|
||||
{
|
||||
base.OnStartClient();
|
||||
|
||||
}
|
||||
|
||||
public void SetName(string oldName, string newName)
|
||||
@@ -56,8 +66,11 @@ public class Player : NetworkBehaviour
|
||||
}
|
||||
public void RemoveHealth(int value)
|
||||
{
|
||||
|
||||
|
||||
if (isAlive)
|
||||
{
|
||||
Debug.Log("yeet" + value);
|
||||
health -= value;
|
||||
if (health <= 0)
|
||||
{
|
||||
|
||||
@@ -84,7 +84,6 @@ public class PlayerController : NetworkBehaviour
|
||||
}
|
||||
|
||||
groundAngle = Vector3.Angle(hit.normal,transform.up);
|
||||
Debug.Log(moveGroundAngle);
|
||||
}
|
||||
}
|
||||
private void Sprint()
|
||||
@@ -118,7 +117,7 @@ public class PlayerController : NetworkBehaviour
|
||||
if (Input.GetButtonDown("Jump") && isGrounded)
|
||||
{
|
||||
//Debug.Log("Jump");
|
||||
velocityY += Mathf.Sqrt(jumpHeight * 4f);
|
||||
velocityY += Mathf.Sqrt(jumpHeight * -2f * gravity);
|
||||
}
|
||||
|
||||
inputDirection = new Vector3(Input.GetAxisRaw("Horizontal"),0, Input.GetAxisRaw("Vertical")); //Get Inputs
|
||||
|
||||
@@ -37,6 +37,7 @@ public class PlayerMouseLook : NetworkBehaviour
|
||||
|
||||
playerCamera.gameObject.SetActive(true);
|
||||
|
||||
|
||||
if (lockCursor)
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
|
||||
69
Assets/Scripts/Weapons/Shoot.cs
Normal file
69
Assets/Scripts/Weapons/Shoot.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
|
||||
public class Shoot : NetworkBehaviour
|
||||
{
|
||||
[SerializeField] GameObject muzzle;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Mouse0))
|
||||
{
|
||||
//CmdFireBullet();
|
||||
RpcOnFire();
|
||||
Debug.Log("Hit Left Mouse ");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
|
||||
if (!Input.GetKeyDown(KeyCode.Mouse0))
|
||||
{
|
||||
Gizmos.color = Color.red;
|
||||
}
|
||||
else
|
||||
{
|
||||
Gizmos.color = Color.green;
|
||||
}
|
||||
Gizmos.DrawRay(muzzle.transform.position, muzzle.transform.forward);
|
||||
|
||||
}
|
||||
|
||||
[Command]
|
||||
// This code will be executed on the server.
|
||||
private void CmdFireBullet()
|
||||
{
|
||||
GameObject dedplayer;
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(muzzle.transform.position, muzzle.transform.forward, out hit))
|
||||
{
|
||||
|
||||
if (hit.transform.gameObject.GetComponent<Player>() != null)
|
||||
{
|
||||
Debug.Log("Hit player: " + hit.transform.gameObject.name);
|
||||
dedplayer = hit.transform.gameObject;
|
||||
//dedplayer.GetComponent<Player>().health -= 20;
|
||||
dedplayer.GetComponent<Player>().RemoveHealth(20);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Client]
|
||||
// This code will be executed on the Client.
|
||||
void RpcOnFire()
|
||||
{
|
||||
CmdFireBullet();
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Weapons/Shoot.cs.meta
Normal file
11
Assets/Scripts/Weapons/Shoot.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc5bc2b49bd326e4db460a6a3af59311
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user