Esempio n. 1
0
 void switch1(GameObject go, Vector3 currpos)
 {
     if (gold.balance >= gold.build_cost)
     {
         GameObject.Destroy(go);
         GameObject hello = GameObject.Instantiate(building_pf, currpos, Quaternion.identity, bh_transform);
         hello.AddComponent <AudioSource>();
         hello.GetComponent <Building>().parent_grid = gameObject;
         newmove = g.transform.position;
         state   = 1;
     }
     else
     {
         ng.Fade();
     }
 }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        //Code to be place in a MonoBehaviour with a GraphicRaycaster component
        //GraphicRaycaster gr = graycast;
        //Create the PointerEventData with null for the EventSystem
        //PointerEventData ped = new PointerEventData(null);
        //Set required parameters, in this case, mouse position
        //ped.position = Input.mousePosition;
        //Create list to receive all results
        //List<RaycastResult> results = new List<RaycastResult>();
        //Raycast it

        /*PointerEventData ped = new PointerEventData(null);
         * ped.position = Input.mousePosition;
         * List<RaycastResult> results = new List<RaycastResult>();
         * GraphicRaycaster gr = cam.GetComponent<GraphicRaycaster>();
         * gr.Raycast(ped, results);
         * if (results.Count > 0){
         *  print("hi123");
         * }*/
        /*RaycastHit hit;
         * Ray ray = cam.GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
         * if (Physics.Raycast(ray, out hit, 1000f)){
         *  if (hit.collider.tag == "button"){
         *      print("hi213");
         *  }
         * }*/

        g1s = group1.GetComponent <MouseEnterStore>().state;
        g2s = group2.GetComponent <MouseEnterStore>().state;
        g3s = group3.GetComponent <MouseEnterStore>().state;

        if (awake == true)
        {
            /*RaycastHit hit;
             * Ray ray;
             * if (Input.GetMouseButtonDown(0)){
             *  print("hi");
             *  ray = cam.GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
             *  if (Physics.Raycast(ray, out hit)){
             *      CheckMouseHit(ray, hit, group);
             *  }
             *
             * }*/

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                awake = false;
                blocker.SetActive(false);

                /*tss.first.GetComponent<CanvasGroup>().alpha = 0;
                *  tss.second.GetComponent<CanvasGroup>().alpha = 0;
                *  tss.third.GetComponent<CanvasGroup>().alpha = 0;*/
                tss.GetComponent <CanvasGroup>().alpha = 1;
                turretshop.SetActive(false);

                Vector3    grid_pos = currpos - g.transform.position;
                GameObject currcube = g.gameObject.transform.GetChild((int)grid_pos.x * g.h + (int)grid_pos.z).gameObject;
                currcube.GetComponent <Renderer>().material = cubenolight;


                GameObject highlighter = g.gameObject.transform.GetChild(g.gameObject.transform.childCount - 1).gameObject;
                Color      c           = Color.white;
                c.a = 0f;
                highlighter.GetComponent <Renderer>().material.color = c;
            }

            if (state == 0)
            {
                if (gold.balance >= gold.turr_cost)
                {
                    /*Vector3 mousepos = Input.mousePosition;
                     * mousepos.z = cam.transform.position.z;
                     * Vector3 mp = GetWorldPositionOnPlane(mousepos, 0f);
                     * Vector3 currpos = Gridize(new Vector3(mp.x, 0, mp.z));*/
                    // press 1 key to spawn a passive building
                    if (/*Input.GetKeyDown(KeyCode.Alpha1) ||*/ (g1s == 1))
                    {
                        tss.GetComponent <CanvasGroup>().alpha = 1;
                        GameObject hello = GameObject.Instantiate(turr_pf1, currpos, Quaternion.identity, bh_transform);
                        //hello.transform.position = new Vector3(0, 2, 0);
                        hello.AddComponent <AudioSource>();
                        hello.GetComponent <Building>().parent_grid = gameObject;
                        newmove = g.transform.position;
                        state   = 1;
                    }
                    if (/*Input.GetKeyDown(KeyCode.Alpha2) ||*/ (g2s == 1))
                    {
                        if (tss.missile)
                        {
                            tss.GetComponent <CanvasGroup>().alpha = 1;
                            GameObject hello = GameObject.Instantiate(turr_pf2, currpos, Quaternion.identity, bh_transform);
                            //hello.transform.position = new Vector3(0, 2, 0);
                            hello.AddComponent <AudioSource>();
                            hello.GetComponent <Building>().parent_grid = gameObject;
                            newmove = g.transform.position;
                            state   = 2;
                        }
                    }
                    if (/*Input.GetKeyDown(KeyCode.Alpha3) ||*/ (g3s == 1))
                    {
                        if (tss.slow)
                        {
                            tss.GetComponent <CanvasGroup>().alpha = 1;
                            GameObject hello = GameObject.Instantiate(turr_pf3, currpos, Quaternion.identity, bh_transform);
                            //hello.transform.position = new Vector3(0, 2, 0);
                            hello.AddComponent <AudioSource>();
                            hello.GetComponent <Building>().parent_grid = gameObject;
                            newmove = g.transform.position;
                            state   = 3;
                        }
                    }
                }
                else
                {
                    ng.Fade();
                }
            }
            else
            {
                GameObject go = GameObject.FindObjectOfType <AudioSource>().gameObject;
                // code for moving with mouse

                /*Vector3 mousepos = Input.mousePosition;
                 * mousepos.z = cam.transform.position.z;
                 * Vector3 mp = GetWorldPositionOnPlane(mousepos, 0f);
                 * Vector3 currpos = Gridize(new Vector3(mp.x, 0, mp.z));    */

                if (Input.GetKeyDown(KeyCode.Escape))
                {
                    tss.GetComponent <CanvasGroup>().alpha = 0;

                    state = 0;
                    awake = false;
                    blocker.SetActive(false);
                    turretshop.SetActive(false);
                    GameObject highlighter = g.gameObject.transform.GetChild(g.gameObject.transform.childCount - 1).gameObject;
                    Color      c           = Color.white;
                    c.a = 0f;
                    highlighter.GetComponent <Renderer>().material.color = c;
                    Object.Destroy(go);
                }

                // if we are currently in state 1 and select a different tower
                if (state == 1)
                {
                    if (/*Input.GetKeyDown(KeyCode.Alpha2) ||*/ (g2s == 1))
                    {
                        if (tss.missile)
                        {
                            group1.GetComponent <MouseEnterStore>().state = 0;

                            /*tss.first.GetComponent<CanvasGroup>().alpha = 0;
                             * tss.second.GetComponent<CanvasGroup>().alpha = 1;*/
                            GameObject.Destroy(go);
                            GameObject hello = GameObject.Instantiate(turr_pf2, currpos, Quaternion.identity, bh_transform);
                            //Vector3 pos = new Vector3(0, 2, 0);
                            hello.AddComponent <AudioSource>();
                            hello.GetComponent <Building>().parent_grid = gameObject;
                            newmove = g.transform.position;
                            state   = 2;
                        }
                    }
                    if (/*Input.GetKeyDown(KeyCode.Alpha3) ||*/ (g3s == 1))
                    {
                        if (tss.slow)
                        {
                            group1.GetComponent <MouseEnterStore>().state = 0;

                            /*tss.first.GetComponent<CanvasGroup>().alpha = 0;
                            *  tss.third.GetComponent<CanvasGroup>().alpha = 1;*/
                            GameObject.Destroy(go);
                            GameObject hello = GameObject.Instantiate(turr_pf3, currpos, Quaternion.identity, bh_transform);
                            //hello.transform.position = new Vector3(0, 2, 0);
                            hello.AddComponent <AudioSource>();
                            hello.GetComponent <Building>().parent_grid = gameObject;
                            newmove = g.transform.position;
                            state   = 3;
                        }
                    }
                }
                // if we are currently in state 2 and select a different tower
                if (state == 2)
                {
                    if (/*Input.GetKeyDown(KeyCode.Alpha1) ||*/ (g1s == 1))
                    {
                        group2.GetComponent <MouseEnterStore>().state = 0;

                        /*tss.second.GetComponent<CanvasGroup>().alpha = 0;
                         * tss.first.GetComponent<CanvasGroup>().alpha = 1;*/
                        GameObject.Destroy(go);
                        GameObject hello = GameObject.Instantiate(turr_pf1, currpos, Quaternion.identity, bh_transform);
                        //hello.transform.position = new Vector3(0, 2, 0);
                        hello.AddComponent <AudioSource>();
                        hello.GetComponent <Building>().parent_grid = gameObject;
                        newmove = g.transform.position;
                        state   = 1;
                    }
                    if (/*Input.GetKeyDown(KeyCode.Alpha3) ||*/ (g3s == 1))
                    {
                        if (tss.slow)
                        {
                            group2.GetComponent <MouseEnterStore>().state = 0;

                            /*tss.third.GetComponent<CanvasGroup>().alpha = 1;
                             * tss.second.GetComponent<CanvasGroup>().alpha = 0;*/
                            GameObject.Destroy(go);
                            GameObject hello = GameObject.Instantiate(turr_pf3, currpos, Quaternion.identity, bh_transform);
                            //hello.transform.position = new Vector3(0, 2, 0);
                            hello.AddComponent <AudioSource>();
                            hello.GetComponent <Building>().parent_grid = gameObject;
                            newmove = g.transform.position;
                            state   = 3;
                        }
                    }
                }
                // if we are currently in state 3 and select a different tower
                if (state == 3)
                {
                    if (/*Input.GetKeyDown(KeyCode.Alpha2) ||*/ (g2s == 1))
                    {
                        if (tss.missile)
                        {
                            group3.GetComponent <MouseEnterStore>().state = 0;

                            /*tss.second.GetComponent<CanvasGroup>().alpha = 1;
                             * tss.third.GetComponent<CanvasGroup>().alpha = 0;*/
                            GameObject.Destroy(go);
                            GameObject hello = GameObject.Instantiate(turr_pf2, currpos, Quaternion.identity, bh_transform);
                            //hello.transform.position = new Vector3(0, 2, 0);
                            hello.AddComponent <AudioSource>();
                            hello.GetComponent <Building>().parent_grid = gameObject;
                            newmove = g.transform.position;
                            state   = 2;
                        }
                    }
                    if (/*Input.GetKeyDown(KeyCode.Alpha1)||*/ (g1s == 1))
                    {
                        group3.GetComponent <MouseEnterStore>().state = 0;

                        /*tss.third.GetComponent<CanvasGroup>().alpha = 1;
                        *  tss.first.GetComponent<CanvasGroup>().alpha = 0;*/
                        GameObject.Destroy(go);
                        GameObject hello = GameObject.Instantiate(turr_pf1, currpos, Quaternion.identity, bh_transform);
                        //hello.transform.position = new Vector3(0, 2, 0);
                        hello.AddComponent <AudioSource>();
                        hello.GetComponent <Building>().parent_grid = gameObject;
                        newmove = g.transform.position;
                        state   = 1;
                    }
                }

                //go.transform.position = Gridize(new Vector3(mp.x, 0, mp.z));
                go.transform.position = currpos;
                if (Input.GetMouseButtonDown(0) || (group1.GetComponent <MouseEnterStore>().clicked == 1) || (group2.GetComponent <MouseEnterStore>().clicked == 1) || (group3.GetComponent <MouseEnterStore>().clicked == 1))
                {
                    Vector3 grid_pos = go.transform.position - g.transform.position;

                    if (!Occupied(grid_pos))
                    {
                        tss.GetComponent <CanvasGroup>().alpha = 0;

                        /*tss.first.GetComponent<CanvasGroup>().alpha = 0;
                        *  tss.second.GetComponent<CanvasGroup>().alpha = 0;
                        *  tss.third.GetComponent<CanvasGroup>().alpha = 0;*/
                        group1.GetComponent <MouseEnterStore>().state = 0;
                        group2.GetComponent <MouseEnterStore>().state = 0;
                        group3.GetComponent <MouseEnterStore>().state = 0;

                        GameObject currcube = g.gameObject.transform.GetChild((int)grid_pos.x * g.h + (int)grid_pos.z).gameObject;
                        currcube.GetComponent <Renderer>().material = cubenolight;

                        turretshop.SetActive(false);
                        Occupy(grid_pos);
                        state = 0;
                        awake = false;
                        go.GetComponent <Turret>().awake   = true;
                        go.GetComponent <Building>().alive = true;
                        gold.balance -= gold.turr_cost;
                        blocker.SetActive(false);
                        GameObject highlighter = g.gameObject.transform.GetChild(g.gameObject.transform.childCount - 1).gameObject;
                        Color      c           = Color.white;
                        c.a = 0f;
                        highlighter.GetComponent <Renderer>().material.color = c;
                    }
                }
            }
        }
    }