public UnitBlockDestructionCommand(Vector3 positionAtDestruction, Quaternion rotationAtDestruction, Color colorAtDestruction, Vector3Int positionInMap, GameObject gameObject, BreakBlockAudioSourceController breakAudio) { this.positionAtDestruction = positionAtDestruction; this.rotationAtDestruction = rotationAtDestruction; this.colorAtDestruction = colorAtDestruction; this.positionInMap = positionInMap; this.gameObject = gameObject; this.breakAudio = breakAudio; // BlockUnit を BlockUnitController に持たせて、ここに渡すと、BlockUnit が Destroy されると同時に BlockUnit のアドレスも消されてしまって Null参照になってしまったので、そこを解決するために BlockCollectionController という永遠に死なないやつから持ってくることにした this.BlockUnit = BlockCollectionController.Instance.BlockUnit; blockCollectionController = BlockCollectionController.Instance; }
// Update is called once per frame void Update() { // ScoreController のほうが先に生成されるので、 blockCollection や sculptureModel の Instance が作られるまで更新する if (blockCollection == null || sculptureModel == null) { blockCollection = BlockCollectionController.Instance; sculptureModel = SculptureModelController.Instance; if (blockCollection == null || sculptureModel == null) { return; } // クライアント側でそれぞれ走らせるものだから、ここで実行させる InitializeScore(); } }
/// <summary> /// スコア初期化の /// </summary> public void InitializeScore() { blockCollection = BlockCollectionController.Instance; sculptureModel = SculptureModelController.Instance; print("there are ScoreController instance"); score = 0; for (int i = 0; i < sculptureModel.sculptureMap.Length; i++) { for (int j = 0; j < sculptureModel.sculptureMap[0].Length; j++) { for (int k = 0; k < sculptureModel.sculptureMap[0][0].Length; k++) { if (sculptureModel.sculptureMap[i][j][k] == blockCollection.blockCollectionMap[i][j][k]) { score++; } } } } scoreText.text = "Score: " + score.ToString(); haveInitialized = true; }
/// <summary> /// Called by Unity when destroying a MonoBehaviour. Scripts that extend /// SingleInstance should be sure to call base.OnDestroy() to ensure the /// underlying static _Instance reference is properly cleaned up. /// </summary> protected virtual void OnDestroy() { _Instance = null; }