private void init() { pimple = GetComponent <Pimple>(); if (pimple == null) { Debug.LogError("Pimple Interact missing Pimple Script"); } }
public void EndDash(bool silent) { dashRemaining = 0; dashing = false; target = null; if (!silent) { dashEnded.Invoke(); } }
private void init() { pimple = GetComponent <Pimple>(); if (pimple == null) { Debug.LogError("PimpleScaler missing pimple reference"); } if (pimpleMesh == null) { Debug.LogError("PimpleScaler missing mesh reference"); } }
private void Update() { var dashTo = transform.forward; if (allowInput && !dashing) { if (target != null) { target.onPopped.RemoveListener(EndDash); } target = null; if (Input.GetAxis("Fire1") > 0) { if (requireTarget && pimpleSpawner != null) { var pimples = pimpleSpawner.Pimples; float minCos = Mathf.Cos(pimpleSpotAngle); float nearestSqrDist = -1; foreach (var pimple in pimples) { if (pimple != null && pimple.ReadyToLance) { var toPimple = pimple.transform.position - transform.position; if (toPimple.sqrMagnitude <= pimpleSpotDistance * pimpleSpotDistance) { var pimplePlanarDireciton = (toPimple - Vector3.Project(toPimple, transform.up)).normalized; var cos = Vector3.Dot(transform.forward, pimplePlanarDireciton); if (cos >= minCos) { if (nearestSqrDist < 0 || (toPimple.sqrMagnitude < nearestSqrDist)) { nearestSqrDist = toPimple.sqrMagnitude; target = pimple; target.onPopped.AddListener(EndDash); dashTo = pimplePlanarDireciton; cachedSqrDist = nearestSqrDist; } } } } } } if (!requireTarget || target != null) { dashing = true; dashRemaining = dashTime; dashTo *= dashModifier; dashStarted.Invoke(dashTo); } } } if (dashing) { bool hasTarget = target != null && !target.Popped; if (hasTarget && (target.transform.position - transform.position).sqrMagnitude > cachedSqrDist) { hasTarget = false; } if (dashRemaining > 0 || hasTarget) { dashRemaining -= Time.deltaTime; } else { EndDash(); } } }