Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        buildable = GlobalDataSet.Coal >= CostCoal && GlobalDataSet.Stone >= CostStone && GlobalDataSet.Iron >= CostIron && GlobalDataSet.CrystalDida >= CostDida &&
                    GlobalDataSet.CrystalGale >= CostGale;
        this.GetComponent <Button>().interactable = buildable;


        if (buildModeActive && !EventSystem.current.IsPointerOverGameObject() && GlobalDataSet.BuildModeActive == this.gameObject)
        {
            Vector3    mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f);
            Ray        ray      = Camera.main.ScreenPointToRay(mousePos);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 9999))
            {
                if (Type == scr_Attributes.Attribute.Extractor && hit.collider.GetComponent <I_IBuildableExtractor>() != null)
                {
                    previewObject.transform.position = hit.collider.transform.Find("BuildPos").position;
                    oreType = hit.collider.GetComponent <scr_UI_BuildingExtractor>().GetOreType();
                }

                if (Type == scr_Attributes.Attribute.Generator && hit.collider.GetComponent <I_IBuildableGenerator>() != null)
                {
                    previewObject.transform.position = hit.collider.transform.Find("BuildPos").position;
                }

                if (Type == scr_Attributes.Attribute.Tower && hit.collider.GetComponent <I_IBuildableGenerator>() != null)
                {
                    previewObject.transform.position = hit.collider.transform.Find("BuildPos").position;
                }
            }

            buildPosOK = previewObject.GetComponent <scr_UI_BuildingPreObjects>().Buildable;


            if (buildPosOK && Input.GetMouseButtonDown(0))
            {
                GameObject buildObject = Instantiate(BuildObject);
                if (Type == scr_Attributes.Attribute.Extractor)
                {
                    buildObject.GetComponent <I_IExtractor>().SetRessourceToTake(oreType);
                }
                buildObject.transform.position = previewObject.transform.position;
                Destroy(previewObject);
                buildModeActive = false;
                buildPosOK      = false;
                GlobalDataSet.BuildModeActive = null;
            }
            else if (!buildPosOK && Input.GetMouseButtonDown(0))
            {
                Destroy(previewObject);
                buildModeActive = false;
                buildPosOK      = false;
                RefundCosts();
                GlobalDataSet.BuildModeActive = null;
            }
        }
    }
Beispiel #2
0
    void Awake()
    {
        scr_Attributes.Attribute ressourcePerScondEnum = scr_Attributes.Attribute.Coal_per_second;
        Renderer materialRenderer = _MaterialParticleSystem.GetComponent <Renderer>();

        switch (resourceToTake)
        {
        case scr_Attributes.Attribute.Coal:
            ressourcePerScondEnum     = scr_Attributes.Attribute.Coal_per_second;
            materialRenderer.material = _ColeMaterial;
            break;

        case scr_Attributes.Attribute.Dida:
            ressourcePerScondEnum     = scr_Attributes.Attribute.Dida_per_second;
            materialRenderer.material = _DidaMaterial;
            break;

        case scr_Attributes.Attribute.Gale:
            ressourcePerScondEnum     = scr_Attributes.Attribute.Gale_per_second;
            materialRenderer.material = _GaleMaterial;
            break;

        case scr_Attributes.Attribute.Iron:
            ressourcePerScondEnum     = scr_Attributes.Attribute.Iron_per_second;
            materialRenderer.material = _IronMaterial;
            break;

        case scr_Attributes.Attribute.Stone:
            ressourcePerScondEnum     = scr_Attributes.Attribute.Stone_per_second;
            materialRenderer.material = _StoneMaterial;
            break;
        }

        ressourcePerSecond = _Stats.Attributes.Find(x => x.Name == ressourcePerScondEnum);
        healthMax          = _Stats.Attributes.Find(x => x.Name == scr_Attributes.Attribute.Maximum_Health);
        health             = GetComponent <scr_DataSet>().Attributes.Find(x => x.Name == scr_Attributes.Attribute.Health);
        energyCost         = _Stats.Attributes.Find(x => x.Name == scr_Attributes.Attribute.Cost_Energy);

        health.Value = healthMax.Value;
        timeLeft     = 1;

        animator             = GetComponent <Animator>();
        _StatsGlobal.Energy -= (int)energyCost.Value;
    }
Beispiel #3
0
 public void SetRessourceToTake(scr_Attributes.Attribute ressourceToTake)
 {
     resourceToTake = ressourceToTake;
 }