Skip to content

Commit

Permalink
Tiny code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ddabble committed Nov 24, 2021
1 parent 2254ee1 commit e3f727b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Assets/Scripts/Player/PlayerSpecificManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class PlayerSpecificManager : MonoBehaviour
{
private static int playerNum = 0;
private static int playerCount = 0;
private int playerIndex;
private PlayerInput input;

Expand All @@ -17,8 +17,7 @@ public class PlayerSpecificManager : MonoBehaviour

void Awake()
{
playerIndex = playerNum;
playerNum++;
playerIndex = playerCount++;
input = GetComponent<PlayerInput>();
}

Expand All @@ -30,7 +29,8 @@ void Start()

public void InitializePlayer()
{
instantiatedPlayer = Instantiate(playerPrefabs[playerIndex%playerPrefabs.Length], spawnPoint, Quaternion.identity).GetComponent<PlayerStateController>();
GameObject playerToSpawn = playerPrefabs[playerIndex % playerPrefabs.Length];
instantiatedPlayer = Instantiate(playerToSpawn, spawnPoint, playerToSpawn.transform.rotation).GetComponent<PlayerStateController>();
instantiatedPlayer.SetUpInput(input, this);
CameraFocusController.Singleton.AddFocusObject(instantiatedPlayer.transform);
}
Expand Down
15 changes: 8 additions & 7 deletions Assets/Scripts/Player/PlayerStateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void OnDestroy()
private void Die(DamageInfo dmg)
{
// Drop anything we are carrying
if (liftedObject != null)
if (liftedObject)
liftedObject.GetComponent<Interactable>().Interact(this);

SetState(PlayerStates.DEAD);
Expand Down Expand Up @@ -154,7 +154,7 @@ private void UpdateConstructionTowerTargetCell()
void OnTriggerEnter(Collider other)
{
Interactable interactable = other.GetComponentInParent<Interactable>();
if (interactable != null && interactable.canInteract)
if (interactable && interactable.canInteract)
AddInteractable(interactable);
}

Expand Down Expand Up @@ -307,13 +307,14 @@ private void UpdateFocusedInteractable()

// Otherwise get closest interactable
Interactable closest = focusedInteractable;
float dist = (focusedInteractable.transform.position - transform.position).sqrMagnitude;
foreach (Interactable i in interactables)
float closestDistSqr = (focusedInteractable.transform.position - transform.position).sqrMagnitude;
foreach (Interactable interactable in interactables)
{
if ((i.transform.position - transform.position).sqrMagnitude < dist)
float distSqr = (interactable.transform.position - transform.position).sqrMagnitude;
if (distSqr < closestDistSqr)
{
dist = (i.transform.position - transform.position).sqrMagnitude;
closest = i;
closestDistSqr = distSqr;
closest = interactable;
}
}

Expand Down

0 comments on commit e3f727b

Please sign in to comment.