|
@@ -8,28 +8,35 @@ public class Station : MonoBehaviour
|
|
|
public Transform gauge;
|
|
public Transform gauge;
|
|
|
public float powerSuckDelay = 1;
|
|
public float powerSuckDelay = 1;
|
|
|
public float powerLevel;
|
|
public float powerLevel;
|
|
|
|
|
+ public float randomRayOffset;
|
|
|
|
|
|
|
|
public LineRenderer lineRenderer;
|
|
public LineRenderer lineRenderer;
|
|
|
|
|
|
|
|
private IEnumerator drainCoroutine;
|
|
private IEnumerator drainCoroutine;
|
|
|
private Transform lineTarget;
|
|
private Transform lineTarget;
|
|
|
|
|
+ public float maxBeamWidth;
|
|
|
|
|
+ public float beamWidthFadeSeconds;
|
|
|
|
|
|
|
|
// Use this for initialization
|
|
// Use this for initialization
|
|
|
- void Start()
|
|
|
|
|
- {
|
|
|
|
|
- powerLevel = 0;
|
|
|
|
|
- lineTarget = lineRenderer.transform;
|
|
|
|
|
|
|
+ void Start ()
|
|
|
|
|
+ {
|
|
|
|
|
+ powerLevel = 0;
|
|
|
|
|
+ lineTarget = lineRenderer.transform;
|
|
|
|
|
+ var midpoint =
|
|
|
|
|
+ (lineRenderer.transform.position +
|
|
|
|
|
+ lineTarget.position)/2;
|
|
|
lineRenderer.SetPositions(new Vector3[]{
|
|
lineRenderer.SetPositions(new Vector3[]{
|
|
|
lineRenderer.transform.position,
|
|
lineRenderer.transform.position,
|
|
|
|
|
+ midpoint,
|
|
|
lineTarget.position,
|
|
lineTarget.position,
|
|
|
});
|
|
});
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Update is called once per frame
|
|
|
|
|
- void Update()
|
|
|
|
|
- {
|
|
|
|
|
- UpdatePowerBar();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ lineRenderer.endWidth = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Update is called once per frame
|
|
|
|
|
+ void Update () {
|
|
|
|
|
+ UpdatePowerBar();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
void PowerUp(float delta)
|
|
void PowerUp(float delta)
|
|
|
{
|
|
{
|
|
@@ -45,16 +52,37 @@ public class Station : MonoBehaviour
|
|
|
{
|
|
{
|
|
|
var level = powerLevel / maxPower;
|
|
var level = powerLevel / maxPower;
|
|
|
gauge.localScale = new Vector3(1, level, 1);
|
|
gauge.localScale = new Vector3(1, level, 1);
|
|
|
- lineRenderer.SetPosition(1, lineTarget.position);
|
|
|
|
|
|
|
+ var midpoint =
|
|
|
|
|
+ (lineRenderer.transform.position +
|
|
|
|
|
+ lineTarget.position)/2;
|
|
|
|
|
+ lineRenderer.SetPosition(1, midpoint + randomRayOffset * Random.onUnitSphere);
|
|
|
|
|
+ lineRenderer.SetPosition(2, lineTarget.position);
|
|
|
|
|
+ lineRenderer.material.mainTextureOffset = new Vector2((4 * Time.time) % 1, 0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void OnTriggerEnter(Collider other)
|
|
void OnTriggerEnter(Collider other)
|
|
|
{
|
|
{
|
|
|
if (other.CompareTag("Player"))
|
|
if (other.CompareTag("Player"))
|
|
|
{
|
|
{
|
|
|
|
|
+ lineRenderer.enabled = true;
|
|
|
lineTarget = other.transform;
|
|
lineTarget = other.transform;
|
|
|
drainCoroutine = DrainPower(other.GetComponent<Player>());
|
|
drainCoroutine = DrainPower(other.GetComponent<Player>());
|
|
|
StartCoroutine(drainCoroutine);
|
|
StartCoroutine(drainCoroutine);
|
|
|
|
|
+ StartCoroutine(LerpBeamEndWidth(maxBeamWidth, beamWidthFadeSeconds));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private IEnumerator LerpBeamEndWidth(float tarvetValue, float duration)
|
|
|
|
|
+ {
|
|
|
|
|
+ float startValue = lineRenderer.endWidth;
|
|
|
|
|
+ for (float t = 0; t < duration; t += Time.deltaTime)
|
|
|
|
|
+ {
|
|
|
|
|
+ lineRenderer.endWidth = Mathf.Lerp(startValue, tarvetValue, t / duration);
|
|
|
|
|
+ yield return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Mathf.Approximately(tarvetValue, 0))
|
|
|
|
|
+ {
|
|
|
|
|
+ lineRenderer.enabled = false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -62,9 +90,10 @@ public class Station : MonoBehaviour
|
|
|
{
|
|
{
|
|
|
if (other.CompareTag("Player"))
|
|
if (other.CompareTag("Player"))
|
|
|
{
|
|
{
|
|
|
- lineTarget = lineRenderer.transform;
|
|
|
|
|
|
|
+ //lineTarget = lineRenderer.transform;
|
|
|
if (drainCoroutine != null)
|
|
if (drainCoroutine != null)
|
|
|
StopCoroutine(drainCoroutine);
|
|
StopCoroutine(drainCoroutine);
|
|
|
|
|
+ StartCoroutine(LerpBeamEndWidth(0, beamWidthFadeSeconds));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|