public void RandomizeBallsInTubes(int randAmount) { for (int i = 0; i < randAmount; i++) { int pickTubeIdA = Random.Range(0, Tubes.Count); TubeAgent pickTubeA = Tubes[pickTubeIdA]; while (pickTubeA.BallCount == 0) { pickTubeIdA = Random.Range(0, Tubes.Count); pickTubeA = Tubes[pickTubeIdA]; } int pickTubeIdB = Random.Range(0, Tubes.Count); while (pickTubeIdB == pickTubeIdA) { pickTubeIdB = Random.Range(0, Tubes.Count); } TubeAgent pickTubeB = Tubes[pickTubeIdB]; while (pickTubeB.BallCount == 4) { pickTubeIdB = Random.Range(0, Tubes.Count); while (pickTubeIdB == pickTubeIdA) { pickTubeIdB = Random.Range(0, Tubes.Count); } pickTubeB = Tubes[pickTubeIdB]; } pickTubeB.PushBall(pickTubeA.PopLastBall()); } for (int i = Tubes.Count - 2; i < Tubes.Count; i++) { TubeAgent tube = Tubes[i]; //for(int n = 0; n < tube.BallCount; n++) while (tube.BallCount > 0) { TubeAgent pickTube = Tubes[Random.Range(0, Tubes.Count - 2)]; while (pickTube.BallCount == 4) { pickTube = Tubes[Random.Range(0, Tubes.Count - 2)]; } pickTube.PushBall(tube.PopLastBall()); } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { Vector2 rayPos = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y); RaycastHit2D hit = Physics2D.Raycast(rayPos, Vector2.zero, 0f); if (hit) { if (hit.transform.tag == "Player") { if (SelectedTube == null) { TubeAgent tube = hit.transform.GetComponent <TubeAgent>(); tube.SelectBall(); SelectedTube = tube; } else { TubeAgent tube = hit.transform.GetComponent <TubeAgent>(); if (tube.BallCount < 4) { BallAgent ball = SelectedTube.PopSelectedBall(); tube.PushBall(ball); SelectedTube = null; //tube.CheckBalls(); if returns true play success animation particle etc. CheckForWin(); } } } } else { if (SelectedTube != null) { SelectedTube.DeSelectBall(); SelectedTube = null; } } } }