public void StopInflating() { if (lifecycle == BalloonLifecycle.Inflating) { lifecycle = BalloonLifecycle.Inflated; BalloonPoint newBalloonPoint = Instantiate(balloonPointPrefab, spawnTarget.position, spawnTarget.rotation, transform).GetComponent <BalloonPoint>(); balloonPoints.Add(newBalloonPoint); // First Point if (lastAddedBallonPoint == null) { lastAddedBallonPoint = newBalloonPoint; } // Next point else { newBalloonPoint.Initialize(this, inflatingTime, currentColour, 0f); Vector3 newDirection = newBalloonPoint.transform.position - lastAddedBallonPoint.transform.position; newDirection.Normalize(); lastAddedBallonPoint.SetNext(newBalloonPoint); newBalloonPoint.SetPrevious(lastAddedBallonPoint); } lastAddedBallonPoint = newBalloonPoint; lastSpawnBalloonPoint = spawnTarget.position; } }
public void StartInflating() { if (lifecycle == BalloonLifecycle.Idle) { lifecycle = BalloonLifecycle.Inflating; } }
public void Initialize(Transform newSpawnTarget) { mRigidBody = GetComponent <Rigidbody>(); visualiser = GetComponent <BalloonVisualiser> (); visualiser.Initialize(this); balloonPoints = new List <BalloonPoint> (); lifecycle = BalloonLifecycle.Idle; spawnTarget = newSpawnTarget; }
private IEnumerator Inflate(float inflatingTime, float targetScale) { localState = BalloonLifecycle.Inflating; float startTime = Time.time; while (Time.time - startTime < inflatingTime) { float lerp = (Time.time - startTime) / inflatingTime; transform.localScale = Vector3.one * lerp * targetScale; yield return(new WaitForEndOfFrame()); } transform.localScale = Vector3.one * targetScale; localState = BalloonLifecycle.Inflated; }
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; }