// 35, 107,179 private void onBallsMoving() { // Move to start Position First Child Balls.BallFiring toPlaceInto = generateBallOn.GetChild(0).GetComponent <Balls.BallFiring>(); generateBallOn.GetChild(0).transform.position = PlayerCenter.position; // Generate new Balls.BallFiring newPrefab = GameObject.Instantiate(prefabsBall); newPrefab.transform.SetParent(generateBallOn, false); newPrefab.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f); newPrefab.transform.position = generateBallOn.GetChild(generateBallOn.childCount - 2).transform.position; newPrefab.AssingRandom(false); NextIsReady = true; MoveAllLeftBalls(); }
void ITouchable.OnPointerUp(PointerEventData eventData) { if (NextIsReady && LevelController.instance.GameStarted) { Vector3 position = eventData.pointerCurrentRaycast.worldPosition; if (position.y > PlayerCenter.position.y) { NextIsReady = false; Balls.BallFiring ToFire = null; ToFire = generateBallOn.GetChild(0).GetComponent <Balls.BallFiring>(); ToFire.transform.localScale = Vector3.one; ToFire.attachedBody = ToFire.gameObject.AddComponent <Rigidbody2D>(); ToFire.attachedBody.freezeRotation = true; Vector2 forceApply = position - PlayerCenter.position; forceApply = forceApply.normalized; forceApply *= Constants.FOrceConstant; ToFire.attachedBody.AddForce(forceApply, ForceMode2D.Impulse); } } }
public BallFiring[] GetAllBallsInRange() { // Make 6 raycasts each 60 degrees // List<BallFiring> allBalsFiring = new List<BallFiring>(); // RaycastHit2D[] allHits = new RaycastHit2D[10]; // float byAngles = 360 / Constants.NumberOfCasts; // Vector2 direction = Vector2.right; // byAngles = Mathf.Deg2Rad * byAngles; // BallFiring temproal = null; // int Allcast = 0; // for (int i = 0; i < Constants.NumberOfCasts; i++) // { // direction = new Vector2( Mathf.Sin(byAngles* i), Mathf.Cos(byAngles * i)); // Debug.LogWarning(" Direction : " + direction); // Allcast = myCollider.Cast(direction,allHits, Constants.RaycastLength); // while(Allcast > 0) // { // temproal = allHits[Allcast-1].transform.gameObject.GetComponent<BallFiring>(); // if (!allBalsFiring.Contains(temproal)) // allBalsFiring.Add(temproal); // Allcast --; // } // } // temproal = null; var circleCast = Physics2D.OverlapCircleAll(this.gameObject.transform.position, Constants.RaycastLength, (int)physicsLayerMask); BallFiring[] listOfFiredBalls = new BallFiring[circleCast.Length]; for (int i = 0; i < listOfFiredBalls.Length; i++) { listOfFiredBalls[i] = circleCast[i].GetComponent <BallFiring>(); } return(listOfFiredBalls); }