Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ddabble committed Oct 16, 2021
1 parent 7f4ce6e commit 37b8cf1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
23 changes: 9 additions & 14 deletions Assets/Scripts/GameState/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ void Awake()
GetComponent<HealthLogic>().onDeath += Die;
anim = GetComponent<Animator>();

if(mainCrystal == null)
{
if (mainCrystal == null)
Debug.LogError("Main Crystal not set.");
}
}

void OnDestroy()
Expand Down Expand Up @@ -131,9 +129,7 @@ private void Die()
StartCoroutine("Explode");

// Start Distortions
//distortionField.enabled = true;


//distortionField.enabled = true;
}

dead = true;
Expand Down Expand Up @@ -184,19 +180,18 @@ public int GetIdVFX(Transform t)
IEnumerator Explode()
{
// Get a list of all transforms (lighning targets)
Transform[] transforms = GameObject.FindObjectsOfType<Transform>();
Transform[] transforms = FindObjectsOfType<Transform>();

// Create lightning as the crystal charges
for (int _ = 0; _ >= explosionLightningCount; _++)
{
int i = Random.Range(0, transforms.Length);

Transform ray = Instantiate(drainRay, transform.position + new Vector3(Random.Range(-1, 1), 5f, Random.Range(-1, 1)), transform.rotation).transform;
ray.SetParent(transform);
Vector3 rayPos = transform.position + new Vector3(Random.Range(-1, 1), 5f, Random.Range(-1, 1));
Transform ray = Instantiate(drainRay, rayPos, transform.rotation, transform).transform;

// 1 is the index of the first child (after the parent itself)
Transform target = ray.GetComponentsInChildren<Transform>()[1];
target.SetParent(transforms[i]);
Transform randomLightningTarget = transforms[Random.Range(0, transforms.Length)];
target.SetParent(randomLightningTarget);
target.localPosition = Vector3.zero;

// Ensure correct camera focus
Expand All @@ -209,7 +204,7 @@ IEnumerator Explode()
GameObject deadBase = Instantiate(destroyedBase, transform.position, Quaternion.identity);

// Add an explosion force on the base
foreach(Rigidbody rb in deadBase.GetComponentsInChildren<Rigidbody>())
foreach (Rigidbody rb in deadBase.GetComponentsInChildren<Rigidbody>())
{
rb.AddForce(new Vector3(Random.Range(-250f, 250f), Random.Range(500f, 800f), Random.Range(-250f, 250f)));
}
Expand All @@ -221,7 +216,7 @@ IEnumerator Explode()
Instantiate(gameOverScreen);

// Add particle system
Instantiate(deathParticles, transform.position + new Vector3(0,3,0), transform.rotation);
Instantiate(deathParticles, transform.position + new Vector3(0, 3, 0), transform.rotation);

// Clean up
Destroy(gameObject);
Expand Down
8 changes: 2 additions & 6 deletions Assets/Scripts/Player/CameraFocusController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,10 @@ private Vector3 boundingBoxCenter()

//Taking the mean sqare avg of the mindistance and box distance
if (!overview)
{
distance = Mathf.Sqrt(radialDist * radialDist + minDistance * minDistance);
}
else
{
distance = Mathf.Sqrt(radialDist * radialDist + overviewDistance * overviewDistance);
}

return center + distance * viewDir;
}

Expand All @@ -109,15 +106,14 @@ public void Focus(Transform obj)

// Switch to overview mode
EnableOverview();

}

public void EnableOverview()
{
if (!overview)
{
overview = true;
smoothing = smoothing / 10;
smoothing /= 10;
}
}
}
3 changes: 1 addition & 2 deletions Assets/Scripts/Player/PlayerUi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public void Select()
if (inventory.ResourceAmount - GetSelectedCost() < 0)
{
state.SetState(PlayerStates.FREE);
}
else
} else
{
inventory.ResourceAmount -= GetSelectedCost();
GameObject spawnedTower = Instantiate(GetSelectedSegment());
Expand Down

0 comments on commit 37b8cf1

Please sign in to comment.