/// <summary> /// Method responsible for getting jelly from the ring manager and transfering it into the slingshot /// </summary> private void GetJelly() { JellyRecruit jelly = JellyRingManager.Instance.GetClosestJelly(); tossableJelly = jelly.GetTossableJelly(); jelly.CreateNewJelly(); tossableJelly.transform.parent = null; iTween.ScaleTo(tossableJelly, iTween.Hash("scale", new Vector3(1f, 1f, 1f), "easeType", "linear", "time", SwapTime)); iTween.RotateTo(tossableJelly, iTween.Hash("rotation", new Vector3(0f, 180f, 0f), "easeType", "linear", "time", SwapTime)); StartCoroutine(MoveToTarget()); //iTween.MoveTo(tossableJelly, iTween.Hash("position", transform, "easeType", "linear", "time", SwapTime, "oncomplete", "OnAnimationEnd", "oncompletetarget", gameObject)); tossIsReady = false; }
/// <summary> /// Gets the jelly that is closest to the player's line of sight /// </summary> public JellyRecruit GetClosestJelly() { float minAngle = 360f; JellyRecruit closestJelly = jellies[0]; foreach (JellyRecruit j in jellies) { Vector3 targetDir = j.transform.position - Camera.main.transform.position; float angleBetween = Vector3.Angle(Camera.main.transform.forward, targetDir); if (angleBetween < minAngle) { minAngle = angleBetween; closestJelly = j; } } return(closestJelly); }