Skip to content

Commit

Permalink
fix: death
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterAzix committed Jan 20, 2023
1 parent e056be2 commit 88d177d
Show file tree
Hide file tree
Showing 7 changed files with 4,238 additions and 757 deletions.
7 changes: 1 addition & 6 deletions Assets/Code/Scripts/PlayerStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override void OnNetworkSpawn()
private void HealthOnValueChanged(int prevHealth, int nextHealth)
{
Debug.Log("prevHealth : " + prevHealth + "newtHealth : " + nextHealth + "ClientId" + OwnerClientId);
if (nextHealth == 0)
if (nextHealth <= 0)
{
KillPlayer();
}
Expand Down Expand Up @@ -61,9 +61,7 @@ private IEnumerator DeathCoroutine()
transform.GetChild(0).GetComponent<PlayerCameraMovement>().enabled = true;
transform.GetComponent<ShootScript>().enabled = true;


ResetHealthServerRpc();

}

[ServerRpc(RequireOwnership = false)]
Expand All @@ -77,8 +75,5 @@ private void AssignPlayerNameServerRpc()
{
networkPlayerName.Value = GameObject.Find("InputName").GetComponent<TMP_InputField>().text;
playerName.text = networkPlayerName.Value.ToString();

}


}
32 changes: 18 additions & 14 deletions Assets/Code/Scripts/bulletScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
public class bulletScript : NetworkBehaviour
{
[SerializeField] float bulletVelocity;
[SerializeField] int bulletDamage = 25;

// Start is called before the first frame update
void Start()
{
Expand All @@ -20,22 +22,27 @@ void Start()

}

private void FixedUpdate()
/* private void FixedUpdate()
{
CheckHit();
}
} */

private void OnCollisionEnter(Collision collision)
{

//if (collision.gameObject.tag == "Player")
//{
if (collision.gameObject.tag == "Player" && IsOwner)
{
var playerHit = collision.gameObject.GetComponent<NetworkObject>();
UpdatePlayerHealthServerRpc(25, playerHit.OwnerClientId);
}
if (IsOwner)
{
DestroyBulletServerRpc();
}

//}

}

private void CheckHit()
/* private void CheckHit()
{
RaycastHit hit;
Expand All @@ -49,23 +56,20 @@ private void CheckHit()
if(playerHit != null && IsOwner)
{
UpdatePlayerHealthServerRpc(10, playerHit.OwnerClientId);
UpdatePlayerHealthServerRpc(25, playerHit.OwnerClientId);
}
if (IsOwner)
{
DestroyBulletServerRpc();
}
}
}
} */

[ServerRpc]
private void DestroyBulletServerRpc()
{
if (IsOwner)
{
gameObject.GetComponent<NetworkObject>().Despawn();
Destroy(gameObject);
}
gameObject.GetComponent<NetworkObject>().Despawn();
Destroy(gameObject);
}

IEnumerator DestroyCoroutine()
Expand Down
50 changes: 29 additions & 21 deletions Assets/Code/Scripts/playerMovement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,34 +61,30 @@ public enum MovementState {
air
}



public override void OnNetworkSpawn()
{


readyToJump = true;
rb = GetComponent<Rigidbody>();
rb.freezeRotation = true;
readyToJump = true;
rb = GetComponent<Rigidbody>();
rb.freezeRotation = true;

startYScale = transform.localScale.y;
startYScale = transform.localScale.y;

spawningPointsArr = GameObject.FindGameObjectsWithTag("SpawningPoint");
spawningPoints = new List<GameObject>(spawningPointsArr);
int spawningPositionIndex = Random.Range(0, spawningPoints.Count);
spawningPointsArr = GameObject.FindGameObjectsWithTag("SpawningPoint");
spawningPoints = new List<GameObject>(spawningPointsArr);
int spawningPositionIndex = Random.Range(0, spawningPoints.Count);

if(IsOwner&& IsLocalPlayer)
{

playerSpawningPoint = spawningPoints[spawningPositionIndex].transform;
transform.position = playerSpawningPoint.position;
Debug.Log("spawning !");

}
spawningPoints.RemoveAt(spawningPositionIndex);

spawningPoints.RemoveAt(spawningPositionIndex);
//SpawnPlayerServerRpc();

}


void Update()
{
Expand All @@ -104,16 +100,16 @@ void Update()
else
rb.drag = 0;
}

}

private void FixedUpdate()
{
if (IsOwner && IsLocalPlayer )
{
MovePlayer();
MovePlayer();
}
}

private void MyInput()
{
horizontalInput = Input.GetAxisRaw("Horizontal");
Expand All @@ -134,6 +130,7 @@ private void MyInput()
transform.localScale = new Vector3(transform.localScale.x, crouchYScale, transform.localScale.z);
rb.AddForce(Vector3.down * 5f, ForceMode.Impulse);
}

if (Input.GetKeyUp(crouchInput))
{
gunObject.localScale = new Vector3(gunObject.localScale.x, 1, gunObject.localScale.z);
Expand Down Expand Up @@ -213,7 +210,7 @@ private void Jump()
exitingSlope = true;
rb.velocity = new Vector3(rb.velocity.x, 0f, rb.velocity.z);

rb.AddForce(transform.up * jumpForce, ForceMode.Impulse );
rb.AddForce(transform.up * jumpForce, ForceMode.Impulse);
}

private void ResetJump()
Expand All @@ -230,8 +227,9 @@ public bool OnSlope()
float angle = Vector3.Angle(Vector3.up, slopeHit.normal);

if (angle < maxSlopeAngle && angle != 0)
Debug.Log(true);
{
return true;
}
}
return false;
}
Expand All @@ -257,10 +255,20 @@ public void SpawnPlayerServerRpc()

public void ResetSpawn()
{
if(IsOwner && IsLocalPlayer)
if (IsLocalPlayer)
{
Debug.Log(playerSpawningPoint);
gameObject.transform.position = playerSpawningPoint.position;
int spawningPositionIndex = Random.Range(0, spawningPoints.Count);
playerSpawningPoint = spawningPoints[spawningPositionIndex].transform;
transform.position = playerSpawningPoint.position;
} else
{
SpawnPlayerServerRpc();
}
/* if (IsOwner && IsLocalPlayer)
{
int spawningPositionIndex = Random.Range(0, spawningPoints.Count);
playerSpawningPoint = spawningPoints[spawningPositionIndex].transform;
gameObject.transform.position = playerSpawningPoint.position;
} */
}
}
2 changes: 1 addition & 1 deletion Assets/Level/Prefabs/Player.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ GameObject:
- component: {fileID: 6231541386680818423}
m_Layer: 6
m_Name: Player
m_TagString: Untagged
m_TagString: Player
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
Expand Down
Loading

0 comments on commit 88d177d

Please sign in to comment.