Duration: | Feb 2020 - June 2020 |
Team Size: | Solo |
Roles: | Design • Code • Art • Sound |
Engine: | Unity |
Technologies: | C# |
Platforms: | Windows |
To create the mining effect I used Unity's line renderer for the laser, and object pooling to spawn dust and flame particle effects. Below is the function which controls the rendering of the laser, the spawning of particles, and appling damage to the asteroid.
public void UpdateMiningLaser(bool keypressed, Vector3 mousepos, Vector3 playerpos)
{
laser1LineRenderer.enabled = false;
laser2LineRenderer.enabled = false;
if (keypressed == false)
return;
RaycastHit2D hit1 = Physics2D.Raycast( gun1.transform.position,
(transform.position + (mousepos - playerpos) * 0.5f) - gun1.transform.position,
25.0f,
1 << LayerMask.NameToLayer("Asteroids"));
RaycastHit2D hit2 = Physics2D.Raycast( gun2.transform.position,
(transform.position + (mousepos - playerpos) * 0.5f) - gun2.transform.position,
25.0f,
1 << LayerMask.NameToLayer("Asteroids"));
if (hit1.collider !=null)
LaserHit(gun1.transform.position, hit1, ref laser1LineRenderer);
if (hit2.collider !=null)
LaserHit(gun2.transform.position, hit2, ref laser2LineRenderer);
void LaserHit(Vector3 origin, RaycastHit2D hit, ref LineRenderer laserLineRenderer)
{
if (hit.collider.CompareTag("Asteroid")==false)
return;
laserLineRenderer.enabled=true;
laserLineRenderer.positionCount=2;
laserLineRenderer.SetPosition(0, origin);
laserLineRenderer.SetPosition(1,hit.point);
ParticleEffects.Instance.SpawnParticles(hit.point, 1, ParticleType.dust);
ParticleEffects.Instance.SpawnParticles(hit.point, 1, ParticleType.fire);
Asteroid asteroid = hit.collider.GetComponentInParent<Asteroid>();
asteroid.Melt(0.2f);
}
}
To create the mining effect I used Unity's line renderer for the laser and object pooling to spawn dust and flame particle effects. Below is the function which controls the rendering of the laser, the spawning of particles, and appling damage to the asteroid.
public void DoMiningLaser(bool keypressed, Vector3 mousepos, Vector3 playerpos)
{
laser1LineRenderer.enabled = false;
laser2LineRenderer.enabled = false;
if (keypressed == false)
return;
RaycastHit2D hit1 = Physics2D.Raycast( gun1.transform.position,
(transform.position + (mousepos - playerpos) * 0.5f) - gun1.transform.position,
25.0f,
1 << LayerMask.NameToLayer("Asteroids"));
RaycastHit2D hit2 = Physics2D.Raycast( gun2.transform.position,
(transform.position + (mousepos - playerpos) * 0.5f) - gun2.transform.position,
25.0f,
1 << LayerMask.NameToLayer("Asteroids"));
if (hit1.collider !=null)
LaserHit(gun1.transform.position, hit1, ref laser1LineRenderer);
if (hit2.collider !=null)
LaserHit(gun2.transform.position, hit2, ref laser2LineRenderer);
void LaserHit(Vector3 origin, RaycastHit2D hit, ref LineRenderer laserLineRenderer)
{
if (hit.collider.CompareTag("Asteroid")==false)
return;
laserLineRenderer.enabled=true;
laserLineRenderer.positionCount=2;
laserLineRenderer.SetPosition(0, origin);
laserLineRenderer.SetPosition(1,hit.point);
ParticleEffects.Instance.SpawnParticles(hit.point, 1, ParticleType.dust);
ParticleEffects.Instance.SpawnParticles(hit.point, 1, ParticleType.fire);
Asteroid asteroid = hit.collider.GetComponentInParent<Asteroid>();
asteroid.Melt(0.2f);
}
}