コード例 #1
0
    void BuildNow(GridTile plantGrid, Vector3 plantPos)
    {
        if (isTurbine) // If we want to build a turbine...
        {
            curInstantiated.GetComponent <TurbineController>().enabled = true;
            world.AddTurbine(curInstantiated, plantPos, curInstantiated.transform.rotation, curInstantiated.GetComponent <SizeController>().desiredScale, GridTileOccupant.OccupantType.Turbine, TurbineManager.GetInstance().transform); // Let the world controller know we want to build this thing
            Renderer[] rens       = curInstantiated.GetComponentsInChildren <Renderer>();
            Renderer[] rensPrefab = curSelected.GetComponentsInChildren <Renderer>();
            int        count      = 0;
            foreach (Renderer ren in curInstantiated.GetComponentsInChildren <Renderer>())
            {
                foreach (Material mat in ren.materials)
                {
                    mat.shader = Shader.Find("Standard");
                    mat.color  = originalMaterial[count];
                    count++;
                }
            }
        }
        else
        {
            world.AddOther(curSelected, plantPos, curInstantiated.transform.rotation, curInstantiated.GetComponent <SizeController>().desiredScale, GridTileOccupant.OccupantType.Other, TerrainController.thisTerrainController.transform);
            Destroy(curInstantiated);
            WindVaneController windVaneController = curInstantiated.GetComponent <WindVaneController>();

            if (windVaneController != null)
            {
                windVaneController.enabled = true;
            }
        }
        GameResources.Buy(curInstantiated.GetComponent <PriceController>().price);
        curInstantiated = null;

        GameObject newObject = new GameObject();

        newObject.transform.parent = Camera.main.transform;
        AudioSource doefAudioSource = newObject.AddComponent <AudioSource>();

        doefAudioSource.clip = doef;
        doefAudioSource.Play();
        inBuildMode = false;
    }