private void Update() { if (lifecycle == BalloonLifecycle.Inflating) { if (Vector3.Distance(lastSpawnBalloonPoint, spawnTarget.position) > newBalloonPointRatio) { BalloonPoint newBalloonPoint = Instantiate(balloonPointPrefab, spawnTarget.position, spawnTarget.rotation, transform).GetComponent <BalloonPoint>(); balloonPoints.Add(newBalloonPoint); // First Point if (lastAddedBallonPoint == null) { newBalloonPoint.Initialize(this, inflatingTime, currentColour, 0f); lastAddedBallonPoint = newBalloonPoint; } // Next point else { newBalloonPoint.Initialize(this, inflatingTime, currentColour, 0.03f); lastAddedBallonPoint.SetNext(newBalloonPoint); newBalloonPoint.SetPrevious(lastAddedBallonPoint); } lastAddedBallonPoint = newBalloonPoint; lastSpawnBalloonPoint = spawnTarget.position; } } else if (lifecycle == BalloonLifecycle.Inflated) { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100f)) { BalloonPoint balloonPoint = hit.collider.GetComponent <BalloonPoint>(); if (balloonPoint != null) { balloonPoint.Pierce(hit.point, deflatingTime, deflatingDelay); } } } } if (lifecycle != BalloonLifecycle.Idle) { visualiser.UpdateMesh(); } }
private IEnumerator Deflate(Vector3 piercePosition, float deflatingTime, float deflatingDelay) { localState = BalloonLifecycle.Deflating; float startTime = Time.time; bool trigerredNeighbours = false; while (Time.time - startTime < deflatingTime) { if (!trigerredNeighbours && Time.time - startTime > deflatingDelay) { if (next != null) { next.Pierce(transform.position, deflatingTime, deflatingDelay); } if (previous != null) { previous.Pierce(transform.position, deflatingTime, deflatingDelay); } trigerredNeighbours = true; } float lerp = (Time.time - startTime) / deflatingTime; Vector3 force = (transform.position - piercePosition).normalized * (1f - lerp) * parent.ForceMultiplier; parent.AddForceAtPosition(force, transform.position); transform.localScale = Vector3.one * (1f - lerp); yield return(new WaitForEndOfFrame()); } transform.localScale = Vector3.zero; }