// Singleton private void Awake() { if (Instance != null && Instance != this) { Destroy(this); // Don't Really want to destroy the whole gameobject return; } Instance = this; }
// Use this for initialization void Start() { animator = GameObject.Find("ShotPower").GetComponent <Animator>(); ballsInMotion = true; spinControl = GameObject.Find("cueSpinBallBig").GetComponent <SpinController>(); cueControllerScript = whiteBallPrefab.GetComponent <CueController>(); // Disable screen dimming Screen.sleepTimeout = SleepTimeout.NeverSleep; //cueControllerScript = GameObject.Find ("WhiteBall").GetComponent <CueController> (); //16 balls = new GameObject[16]; renderers = new MeshRenderer[16]; rigidbodies = new Rigidbody[16]; enabledScripts = new LockZPosition[16]; whiteBallPrefab.transform.tag = "WhiteBall"; balls[0] = whiteBallPrefab; renderers[0] = whiteBallPrefab.GetComponent <MeshRenderer>(); rigidbodies[0] = whiteBallPrefab.GetComponent <Rigidbody>(); enabledScripts[0] = whiteBallPrefab.GetComponent <LockZPosition>(); PoolGameManager.Instance.whiteBall = balls[0]; Rigidbody rigid = balls[0].GetComponent <Rigidbody>(); rigid.maxAngularVelocity = 150; // rigid.useConeFriction = false; //rigid.collisionDetectionMode = CollisionDetectionMode.Discrete; Debug.Log(PoolGameManager.Instance.whiteBall.GetComponent <Rigidbody>().maxAngularVelocity + " MAX ANG"); float radius = ballPrefab.GetComponent <SphereCollider>().radius; int counter = 1; //5 List <int> freeI = new List <int>(); freeI.Add(0); freeI.Add(1); freeI.Add(1); freeI.Add(2); freeI.Add(2); freeI.Add(3); freeI.Add(3); freeI.Add(3); freeI.Add(3); freeI.Add(4); freeI.Add(4); freeI.Add(4); freeI.Add(4); freeI.Add(4); freeI.Add(2); List <int> freeJ = new List <int>(); freeJ.Add(0); freeJ.Add(0); freeJ.Add(1); freeJ.Add(0); freeJ.Add(2); freeJ.Add(0); freeJ.Add(1); freeJ.Add(2); freeJ.Add(3); freeJ.Add(1); freeJ.Add(2); freeJ.Add(3); freeJ.Add(0); freeJ.Add(4); freeJ.Add(1); Vector3[] positions = new Vector3[15]; for (int i = 0; i < 5; i++) { for (int j = 0; j < i + 1; j++) { GameObject ball = Instantiate(ballPrefab); ball.GetComponent <Renderer>().material.SetTexture("_MainTex", texturesArray[counter - 1]); ball.transform.tag = "Ball" + counter.ToString(); balls[counter] = ball; renderers[counter] = ball.GetComponent <MeshRenderer>(); rigidbodies[counter] = ball.GetComponent <Rigidbody>(); enabledScripts[counter] = ball.GetComponent <LockZPosition>(); Rigidbody ballRigidbody = ball.GetComponent <Rigidbody>(); ballRigidbody.maxAngularVelocity = 150; // ballRigidbody.useConeFriction = false; //ballRigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete; if (PoolGameManager.Instance.roomOwner) { int minus = 4; if (counter > 9) { minus = 1; } int iii = Random.Range(0, freeI.Count - minus); if (counter == 1) { iii = freeI.Count - 3; } else if (counter == 9) { iii = freeI.Count - 2; } else if (counter == 8) { iii = freeI.Count - 1; } float posY = ballPrefab.GetComponent <Rigidbody>().transform.position.y + freeI[iii] * (radius * ballPrefab.transform.localScale.x /*0.325f*/); Vector3 position = ballRigidbody.transform.position; position.x += freeI[iii] * (radius * (ball.transform.localScale.x * 2 * 0.9f) * 1.0f); position.y = posY - freeJ[iii] * (radius * (ball.transform.localScale.x * 2) * 1.0f); freeI.RemoveAt(iii); freeJ.RemoveAt(iii); ballRigidbody.transform.position = position; positions[counter - 1] = position; } else { ball.SetActive(false); } //ball.SetActive (false); ballRigidbody.maxAngularVelocity = 150; counter++; //ballRigidbody.Sleep (); } } PoolGameManager.Instance.balls = balls; if (PoolGameManager.Instance.roomOwner) { Debug.Log("Raise 198"); if (!PoolGameManager.Instance.offlineMode) { PhotonNetwork.RaiseEvent(198, positions, true, null); } } else { for (int i = 0; i < PoolGameManager.Instance.initPositions.Length; i++) { PoolGameManager.Instance.balls[i + 1].GetComponent <Rigidbody>().transform.position = PoolGameManager.Instance.initPositions[i]; PoolGameManager.Instance.balls[i + 1].SetActive(true); } } }