Ejemplo n.º 1
0
    void updateIcons(GameObject factory, buildType type)
    {
        if (factory.GetComponent <buildLogic>().playerID == playerID)
        {
            factoryManager tFManager = factory.GetComponent <factoryManager> ();

            if (tFManager.buildList.Count < 1)
            {
                foreach (GameObject icon in buildIcons)
                {
                    icon.SetActive(false);
                }
            }
            else
            {
                Debug.Log("Stage 3");
                int i = 0;
                foreach (Image icon in GUIIcons)
                {
                    if (i < tFManager.buildList.Count)
                    {
                        icon.gameObject.SetActive(true);
                        icon.sprite = tFManager.buildList [i].Type.icon;
                        Debug.Log("Icon Updated");
                        i++;
                    }
                    else
                    {
                        icon.gameObject.SetActive(false);
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
    void initFactoryUI(GameObject factory, int ID)
    {
        fManager = factory.GetComponent <factoryManager> ();
        factoryGUI.SetActive(true);
        factoryTech1.SetActive(true);
        factoryTech2.SetActive(false);
        factoryTech3.SetActive(false);

        // Setup Current Factory Variables

        if (fManager.buildList.Count < 1)
        {
            foreach (GameObject icon in buildIcons)
            {
                icon.SetActive(false);
            }
        }
        else
        {
            Debug.Log("Stage 3");
            int i = 0;
            foreach (Image icon in GUIIcons)
            {
                if (i < fManager.buildList.Count)
                {
                    icon.gameObject.SetActive(true);
                    icon.sprite = fManager.buildList [i].Type.icon;
                    Debug.Log("Icon Updated");
                    i++;
                }
            }
        }
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (growing && amount >= fuelThreshold)
        {
            GameObject     newFactoryNode = Instantiate(myFactory, gameObject.transform.position, Quaternion.identity);
            factoryManager newFactory     = newFactoryNode.GetComponent <factoryManager>();



            gameObject.SetActive(false);
            growing = false;
        }
    }
Ejemplo n.º 4
0
    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.transform.root.CompareTag("Deposit"))
        {
            pathComplete = true;
            DrawPath();

            depositManager myDepositManager = collision.gameObject.transform.root.gameObject.GetComponent <depositManager>();
            if (myDepositManager != null)
            {
                myDepositManager.amount += fuelAmount;
                //Debug.Log("I added: " + fuelAmount);
            }
            Destroy(gameObject);
        }
        else if (collision.gameObject.transform.root.CompareTag("Resource"))
        {
            pathComplete = true;
            DrawPath();

            collision.gameObject.transform.root.gameObject.SetActive(false);
            GameObject     newDepositNode = Instantiate(defaultDeposit, collision.gameObject.transform.root.position, Quaternion.identity);
            depositManager newDeposit     = newDepositNode.GetComponent <depositManager>();
            newDeposit.amount += fuelAmount;
            //Debug.Log("I added: " + fuelAmount);
            Destroy(gameObject);
        }
        else if (collision.gameObject.transform.root.CompareTag("Factory"))
        {
            pathComplete = true;
            DrawPath();

            factoryManager myFactoryManager = collision.gameObject.transform.root.gameObject.GetComponent <factoryManager>();
            if (myFactoryManager != null)
            {
                //myFactoryManager.amount += fuelAmount;
                Debug.Log("I Factorized: " + fuelAmount);
            }
            Destroy(gameObject);
        }
    }
Ejemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            Ray        ray = camera.ScreenPointToRay(Input.mousePosition);


            if (Physics.Raycast(ray, out hit))
            {
                Transform objectHit = hit.transform.root;
                //Debug.Log(objectHit.name);

                if (objectHit.gameObject.CompareTag("Resource"))
                {
                    makingPath = true;
                    originTile = objectHit.gameObject;
                }

                else if (objectHit.gameObject.CompareTag("Factory"))
                {
                    originTile = objectHit.gameObject;
                    launching  = true;
                }
            }
        }
        if (makingPath && Input.GetMouseButton(0))
        {
            //Debug.Log("My Mouse Is Down!");
            RaycastHit hit;
            Ray        ray = camera.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                Transform objectHit = hit.transform.root;
                //Debug.Log(objectHit.name);


                // Do something with the object that was hit by the raycast.
                if (objectHit.gameObject.CompareTag("Tile"))
                {
                    if (CheckAlongPath(objectHit.gameObject))
                    {
                        tempPathTiles.Add(objectHit.gameObject);
                        objectHit.gameObject.tag = "tempPath";
                        lastTile = objectHit.gameObject;
                        objectHit.gameObject.GetComponentInChildren <MeshRenderer>().material.color = Color.gray;
                    }
                }
            }
        }
        if (Input.GetMouseButtonUp(0))
        {
            Debug.Log("My Mouse Is Up!");
            RaycastHit hit;
            Ray        ray = camera.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                Transform objectHit = hit.transform.root;

                // Do something with the object that was hit by the raycast.
                if (makingPath && objectHit.gameObject.CompareTag("PowerSource") && CheckAlongPath(objectHit.gameObject))
                {
                    foreach (GameObject tile in tempPathTiles)
                    {
                        tile.tag = "path";
                        pathTiles.Add(tile);

                        tile.GetComponentInChildren <MeshRenderer>().material.color = Color.blue;
                    }
                    //create new factory at start location
                    GameObject     newFactoryNode = Instantiate(defaultFactory, originTile.gameObject.transform.position, Quaternion.identity);
                    factoryManager newFactory     = newFactoryNode.GetComponent <factoryManager>();
                    newFactory.myPath      = pathTiles;
                    newFactory.powerSource = objectHit.gameObject;
                    newFactory.baseTile    = originTile;
                    originTile.SetActive(false);
                    tempPathTiles.Clear();
                }
                else if (!launching)
                {
                    foreach (GameObject tile in tempPathTiles)
                    {
                        tile.tag = "Tile";
                        tile.GetComponentInChildren <MeshRenderer>().material.color = Color.white;
                    }
                    tempPathTiles.Clear();
                }

                makingPath = false;
            }
            if (launching)
            {
                //set launch vector for factory
                launching = false;
                Vector3 mousePos = Camera.main.ScreenToViewportPoint(Input.mousePosition);
                //mousePos.z = 0.0f;
                Vector3        endPos        = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane));
                Vector3        launchVector  = endPos - originTile.transform.position;
                factoryManager originFactory = originTile.GetComponent <factoryManager>();
                originFactory.launchVector = launchVector;
                //originFactory.LaunchResource(launchVector);
                originFactory.StartCoroutine("spawnTracker");
            }
        }
    }