void Update()
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hitInfo))
        {
            ourHitObject = hitInfo.collider.transform.gameObject;

            if (ourHitObject.tag != "Hex")
            {
                return;
            }

            if (Input.GetMouseButtonDown(0))
            {
                HexInfo hexInfoObject = ourHitObject.GetComponentInChildren <HexInfo>();


                if (!hexInfoObject.Clickable)
                {
                    return;
                }

                if (MoneyManager.Pigment > 0)
                {
                    if (hexInfoObject != null)
                    {
                        MeshRenderer mr = ourHitObject.GetComponentInChildren <MeshRenderer>();

                        if (ColorInHand == 'C' && hexInfoObject.HexColor != 'C')
                        {
                            FindObjectOfType <AudioManager>().Play("Pop1");
                            hexInfoObject.HexColor = 'C';
                            hexInfoObject.SetColorTo(CyanTex);
                            MoneyManager.Pigment -= colorCost;
                        }
                        else if (ColorInHand == 'M' && hexInfoObject.HexColor != 'M')
                        {
                            FindObjectOfType <AudioManager>().Play("Pop2");
                            hexInfoObject.HexColor = 'M';
                            hexInfoObject.SetColorTo(MagentaTex);
                            MoneyManager.Pigment -= colorCost;
                        }
                        else if (ColorInHand == 'Y' && hexInfoObject.HexColor != 'Y')
                        {
                            FindObjectOfType <AudioManager>().Play("Pop3");
                            hexInfoObject.HexColor = 'Y';
                            hexInfoObject.SetColorTo(YellowTex);
                            MoneyManager.Pigment -= colorCost;
                        }
                    }
                }
            }
        }
    }
Beispiel #2
0
    public void BuildTurretOn(HexInfo hex)
    {
        if (MoneyManager.Pigment < turretToBuild.cost)
        {
            Debug.Log("not enough money to build");
            return;
        }

        if (hex.HexColor == 'W')
        {
            Debug.Log("Can't buil in a empty hex, it must have a color!! :D");
            return;
        }

        MoneyManager.Pigment -= turretToBuild.cost;

        turretToBuild.IncrementNumberOfTurrets();

        GameObject turret = (GameObject)Instantiate(turretToBuild.prefab, hex.gameObject.transform.position + offsetBuild, turretToBuild.prefab.transform.rotation);

        GameObject buildParticles = (GameObject)Instantiate(buildEffect, hex.transform.position, buildEffect.transform.rotation);


        if (turret.GetComponent <TubDePintura>() != null)
        {
            tubScript           = turret.GetComponent <TubDePintura>();
            tubScript.actualHex = hex;
            tubScript.tubColor  = hex.HexColor;
            hex.HexColor        = 'W';
            FindObjectOfType <AudioManager>().Play("Construcció");
            hex.SetColorTo(defaultTexture);
        }
        else if (turret.GetComponent <SpraiScript>() != null)
        {
            spraiScript            = turret.GetComponent <SpraiScript>();
            spraiScript.actualHex  = hex;
            spraiScript.spraiColor = hex.HexColor;
            hex.HexColor           = 'W';
            FindObjectOfType <AudioManager>().Play("Construcció");
            hex.SetColorTo(defaultTexture);
        }

        //S'HA DE POSAR HEX.TURRET DESPRÉS DE TOT ELS IFS PERQUE S'ELIMINI EL COLOR QUAN PINTES
        hex.turret    = turret;
        turretToBuild = null;
    }