// Use this for initialization void Start() { game = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController>(); play = GameObject.FindGameObjectWithTag("Player").transform.GetChild(0).GetComponent <PlayerScript>(); rbody = transform.parent.GetComponentInChildren <Rigidbody>(); disintegration = transform.parent.GetComponentInChildren <DisintegrationScript>(); colorCon = GetComponent <ColorController>(); colliders = GetComponentsInChildren <Collider>(); if (PlayerScript.moveCount == 0) { moveCountAtSpawnTime = -2; } }
public IEnumerator Launch() { //Check how many spawned objects are not disintegrated yet int spawnedObjectsStillAlive = 0; foreach (GameObject obj in spawnedObjects) { if (!obj.GetComponentInChildren <MoveableScript>().isFall) { spawnedObjectsStillAlive++; } } if (spawnedObjectsStillAlive < maxNumberOfObjectsInGame) { GameObject ins = Instantiate(launchObject, transform.position, Quaternion.identity, game.transform.root); PlayerScript.restrictAllInput = true; PlayerScript.allowRotate = false; game.allowRewind = false; MoveableScript moveable = ins.GetComponentInChildren <MoveableScript>(); moveable.moveCountAtSpawnTime = PlayerScript.moveCount; Rigidbody rbody = ins.GetComponent <Rigidbody>(); rbody.isKinematic = false; rbody.useGravity = true; CalculationResults calc = CalculateLaunchData(ins); rbody.velocity = calc.velocity; DisintegrationScript destroy = ins.GetComponentInChildren <DisintegrationScript>(); destroy.destroyOnObstructedLanding = true; spawnedObjects.Add(ins); game.moveables.Add(moveable); yield return(new WaitForSeconds(calc.time)); if (ins != null) { destroy.destroyOnObstructedLanding = false; rbody.isKinematic = true; rbody.useGravity = false; ins.transform.position = targetPos; ins.transform.eulerAngles = launchedObjectRotation; } PlayerScript.restrictAllInput = false; PlayerScript.allowRotate = true; game.allowRewind = true; } else { print("TOO MANY OBJECTS IN SCENE - ABOVE SET QUOTA"); moveCountWhenDenied.Add(PlayerScript.moveCount); } }