public void SetItem(GameObject b)
 {
     Debug.Log(b.tag);
     hasPlaced         = false;
     currentBuilding   = Instantiate(b).transform;
     placeableBuilding = currentBuilding.GetComponent <PlaceableBuilding>();
 }
 public void manipulateTree(Vector3 p)
 {
     if (Input.GetMouseButtonDown(0))
     {
         RaycastHit hit = new RaycastHit();
         Ray        ray = new Ray(new Vector3(p.x, 8, p.z), Vector3.down);
         buildingsMask = LayerMask.GetMask("Building");
         if (Physics.Raycast(ray, out hit, Mathf.Infinity, buildingsMask))
         {
             if (placeableBuildingOld != null)
             {
                 placeableBuildingOld.SetSelected(false);
             }
             if (gameState.currentEvent == 2)
             {
                 createdbuildings.Remove(hit.collider.gameObject);
                 Destroy(hit.collider.gameObject);
             }
             else if (gameState.currentEvent == 3)
             {
                 // Debug.Log(createdbuildings.Find(x => x == hit.collider.gameObject));
                 hasPlaced       = false;
                 currentBuilding = hit.collider.gameObject.transform;
             }
             placeableBuildingOld = null;
         }
     }
 }
Ejemplo n.º 3
0
 // Structure selected from build menu
 public void SetItem(GameObject b)
 {
     if (placeableBuildingOld != null)
     {
         placeableBuildingOld.SetSelected(false);
     }
     if (playerResources.lastNode != null)
     {
         playerResources.lastNode.isSelected = false;
     }
     gold = playerResources.gold;
     lumber = playerResources.lumber;
     stone = playerResources.stone;
     iron = playerResources.gold;
     if (!hasPlaced && currentBuilding != null)
     {
         Destroy(currentBuilding.gameObject);
         hasPlaced = true;
     }
     hasPlaced = false;
     currentBuilding = ((GameObject)Instantiate(b)).transform;
     placeableBuilding = currentBuilding.GetComponent<PlaceableBuilding>();
     placeableBuilding.name = placeableBuilding.structureName + " (Pending)";
     if (gold < placeableBuilding.goldCost && lumber < placeableBuilding.lumberCost && stone < placeableBuilding.stoneCost && iron < placeableBuilding.ironCost)
     {
         Debug.Log("Not enough resources!");
         Destroy(currentBuilding.gameObject);
         hasPlaced = true;
     }
 }
Ejemplo n.º 4
0
 public void SetItem(GameObject b)
 {
     isPlaced                  = false;
     currentBuilding           = ((GameObject)Instantiate(b));
     placeableBuilding         = currentBuilding.GetComponent <PlaceableBuilding> ();
     placeableBuildingRenderer = placeableBuilding.GetComponentInChildren <Renderer> ();
 }
Ejemplo n.º 5
0
    public void SetItem(GameObject gameObject)
    {
        hasPlaced = false;
        currentBuilding = ((GameObject)Instantiate(gameObject)).transform;
        placeableBuilding = currentBuilding.GetComponent<PlaceableBuilding>();

        //	Debug.Log ("hasplaced: "+hasPlaced);
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Debug.Log("click");
            RaycastHit hit = new RaycastHit();

            var p   = GetPosition();
            Ray ray = new Ray(new Vector3(p.x, 8, p.z), Vector3.down);
            if (Physics.Raycast(ray, out hit, Mathf.Infinity, buildingsMask))
            {
                hit.collider.gameObject.GetComponent <PlaceableBuilding>().SetSelected(true);
                placeableBuildingOld = hit.collider.gameObject.GetComponent <PlaceableBuilding>();
            }
            else
            {
                if (placeableBuildingOld != null)
                {
                    placeableBuildingOld.SetSelected(false);
                }
            }

            return;
        }

        var position = Vector3.zero;

        if (currentBuilding != null)
        {
            position = currentBuilding.position;
        }

        if (Input.GetMouseButton(0))
        {
            Vector3 p = GetPosition();
            position = new Vector3(p.x, 0, p.z);
        }

        if (currentBuilding != null && !hasPlaced)
        {
            currentBuilding.position = position;

            if (Input.GetMouseButtonUp(0))
            {
                if (IsLegalPosition() == false)
                {
                    FsmVariables.GlobalVariables.GetFsmInt(placeableBuilding.Resource).Value += placeableBuilding.Amount;

                    GameObject.Destroy(currentBuilding.gameObject);
                }

                hasPlaced         = false;
                currentBuilding   = null;
                placeableBuilding = null;
            }
        }
    }
Ejemplo n.º 7
0
 // Check for other Buildings in area
 bool isLegalPosition()
 {
     m_placeableBuilding = go_buildingToBuild.GetComponent <PlaceableBuilding>();
     if (m_placeableBuilding.colliders.Count > 0)
     {
         return(false);
     }
     return(true);
 }
 public void SetItem(GameObject b)
 {
     hasPlaced                    = false;
     building                     = b;
     newBuilding                  = (GameObject)Instantiate(building);
     newBuilding.name             = newBuilding.name.Remove(newBuilding.name.Length - 7) + transform.childCount;
     newBuilding.transform.parent = gameObject.transform;
     currentBuilding              = (newBuilding).transform;
     placeableBuilding            = currentBuilding.GetComponent <PlaceableBuilding>();
 }
Ejemplo n.º 9
0
 void Start()
 {
     //terrainScript = GetComponent<TerrainDeformer>();
     //terrainScript1 = GetComponent<TerrainDeformer1>();
     viewer            = GetComponent <VRViewer>();
     placeableBuilding = GetComponent <PlaceableBuilding>();
     hasPlaced         = false;
     spacePressed      = false;
     moveObject        = false;
     //Cursor.lockState = CursorLockMode.Confined;
 }
Ejemplo n.º 10
0
    void Update()
    {
        //Vector3 m = Input.mousePosition;
        //m = new Vector3(m.x, m.y, transform.position.y);
        //Vector3 p = cam.ScreenToWorldPoint(m);

        if (Input.touchCount > 0)
        {
            Touch   touch = Input.touches[0];
            Vector3 m     = touch.position;
            m = new Vector3(m.x, m.y, 20);
            Vector3 p = cam.ScreenToWorldPoint(m);

            if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Began && hasPlaced == false)
            {
                if (currentBuilding != null && !hasPlaced)
                {
                    currentBuilding.position = new Vector3(p.x, 0, p.z);
                }
            }
            else if (touch.phase == TouchPhase.Ended)
            {
                if (IsValidPosition())
                {
                    hasPlaced = true;
                }
            }
            //TODO: Touch on screen outside building and dismiss GUI
            else if (touch.phase == TouchPhase.Began && hasPlaced == true)
            {
                RaycastHit hit = new RaycastHit();
                Ray        ray = new Ray(new Vector3(p.x, 8, p.z), Vector3.down);
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, buildingMask))
                {
                    if (placeableBuildingOld != null)
                    {
                        placeableBuildingOld.SetSelected(false);
                    }
                    hit.collider.gameObject.GetComponent <PlaceableBuilding>().SetSelected(true);
                    placeableBuildingOld = hit.collider.gameObject.GetComponent <PlaceableBuilding>();
                }
                else
                {
                    if (placeableBuildingOld != null)
                    {
                        placeableBuildingOld.SetSelected(false);
                    }
                }
            }
        }
    }
 public void SetItem(GameObject b, float price)
 {
     hasPlaced = false;
     currentBuilding = ((GameObject)Instantiate(b)).transform;
     currentBuilding.name = b.name;
     placeableBuilding = currentBuilding.GetComponent<PlaceableBuilding>();
     buildingPrice = price;
     foreach (GameObject go in lots) {
         Transform[] allChildren = go.GetComponentsInChildren<Transform>();
         foreach (Transform child in allChildren) {
             if (child.gameObject.name.Contains("Lot_Placement")) {
                 child.gameObject.renderer.enabled = true;
             }
         }
     }
 }
Ejemplo n.º 12
0
    public GameObject SetItem(GameObject b)
    {
        if (currentBuilding != null)
        {
            Destroy(currentBuilding.gameObject);
            if (manager != null)
            {
                manager.Refund();
            }
        }
        hasPlaced = false;
        Debug.Log("Set Item");
        GameObject res = (GameObject)Instantiate(b);

        currentBuilding = res.transform;
        //		GameObject go = transform.Find ("BuildingFootprint").gameObject;
        //		placeableBuilding = (PlaceableBuilding)go;
        placeableBuilding = currentBuilding.GetComponentsInChildren <PlaceableBuilding>()[0];
        placeableBuilding.SetSelected(true);
        return(res);
    }
    public void SetItem(GameObject b)
    {
        Debug.Log("Set item");
        var pb = b.GetComponent <PlaceableBuilding>();

        if (pb == null)
        {
            return;
        }

        var CurrentAmount = FsmVariables.GlobalVariables.GetFsmInt(pb.Resource).Value;

        if (CurrentAmount < pb.Amount)
        {
            return;
        }

        hasPlaced         = false;
        currentBuilding   = ((GameObject)Instantiate(b)).transform;
        placeableBuilding = currentBuilding.GetComponent <PlaceableBuilding>();
    }
Ejemplo n.º 14
0
    public void SetItem(GameObject b)
    {
        if (b.name == "torch")
        {
            hasPlaced = false;

            GameObject childObject = Instantiate(b) as GameObject;
            //Position
            childObject.transform.position = new Vector3(playerHand.transform.position.x, playerHand.transform.position.y, playerHand.transform.position.z);
            //Rotation
            Quaternion rotation = Quaternion.Euler(50, playerHand.transform.rotation.y, playerHand.transform.rotation.z);
            childObject.transform.rotation = rotation;

            childObject.transform.parent = playerHand.transform;
        }
        else
        {
            hasPlaced         = false;
            currentBuilding   = ((GameObject)Instantiate(b)).transform;
            placeableBuilding = currentBuilding.GetComponent <PlaceableBuilding>();
        }
    }
Ejemplo n.º 15
0
 // Use this for initialization
 void Start()
 {
     m_BuildingPlacer    = FindObjectOfType <BuildingPlacer>();
     m_grid              = FindObjectOfType <Grid>();
     m_placeableBuilding = FindObjectOfType <PlaceableBuilding>();
 }
Ejemplo n.º 16
0
    void Update()
    {
        if(currentBuilding != null && !hasPlaced){

            Vector3 m = Input.mousePosition;

            m = new Vector3(m.x, m.y, transform.position.y);
            Vector3  pointcam = camera.ScreenToWorldPoint(m);

            currentBuilding.position = new Vector3(pointcam.x, 0, pointcam.z);

            if(Input.GetMouseButtonDown(0)){
                if(IsLegalPosition()){

                    hasPlaced = true;
                }//iflega

                //Debug.Log("placeableBuilding.colliders.Count: "+placeableBuilding.colliders.Count);

            }//ifdown

        }else{ //placed before

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

            //Debug.DrawRay (ray.origin, ray.direction * 100.0f, Color.green);

            if(Input.GetMouseButtonDown(0)){

                Vector3 m = Input.mousePosition;

                m = new Vector3(m.x, m.y, transform.position.y);
                Vector3  pointcam = camera.ScreenToWorldPoint(m);

                RaycastHit hiter = new RaycastHit();

                Debug.DrawRay(transform.position, pointcam, Color.green);

                Ray ray =  new Ray(new Vector3(pointcam.x, 8, pointcam.z), Vector3.down);//Camera.main.ScreenPointToRay (Input.mousePosition);//new Ray(new Vector3(pointcam.x, 8, pointcam.z), Vector3.down);

                if(Physics.Raycast(ray, out hiter, Mathf.Infinity, buildingsMask)){
                    if(placeableBuildingOld != null){
                        placeableBuildingOld.SetSelected(false);
                    }//old false

                    hiter.collider.gameObject.GetComponent<PlaceableBuilding>().SetSelected(true);
                    placeableBuildingOld = hiter.collider.gameObject.GetComponent<PlaceableBuilding>();

                }else{//endmask

                    if(placeableBuildingOld !=null){

                        placeableBuildingOld.SetSelected(false);

                    }//if

                }//else

            }//if

        }//end else
    }
Ejemplo n.º 17
0
 public void SetItem(GameObject b)
 {
     hasPlaced         = false;
     currentBuilding   = ((GameObject)Instantiate(b)).transform;
     placeableBuilding = currentBuilding.GetComponent <PlaceableBuilding>();
 }
Ejemplo n.º 18
0
    // Update is called once per frame
    void Update()
    {
        Camera  mainCam = GetComponent <Camera> ();
        Vector3 m       = Input.mousePosition;
        //		m = new Vector3(m.x,m.y,transform.position.y);
        //		Vector3 p = mainCam.ScreenToWorldPoint(m);

        Ray   ray = mainCam.ScreenPointToRay(m);
        Plane xz  = new Plane(Vector3.up, new Vector3(0, 0.5f, 0));
        float distance;

        xz.Raycast(ray, out distance);
        Vector3 p = ray.GetPoint(distance);


        //		Vector3 p = new Vector3 (0, 0, 0);
        //		Ray ray = mainCam.ScreenPointToRay (m);
        //		if (Physics.Raycast (ray, out hit, Mathf.Infinity, groundMask)) {
        //			m = new Vector3(m.x,m.y,hit.distance);
        //			p = mainCam.ScreenToWorldPoint(m);
        //		}


        if (currentBuilding != null && !hasPlaced)
        {
            currentBuilding.position = new Vector3(p.x, p.y, p.z);

            if (Input.GetMouseButtonDown(0))
            {
                if (IsLegalPosition(p))
                {
                    Debug.Log("Placing Building");
                    hasPlaced = true;
                    //					placeableBuilding.SetSelected (false);
                    placeableBuilding.SetPlaced(true);
                    placeableBuildingOld = placeableBuilding;
                    currentBuilding      = null;
                }
            }
            else if (Input.GetMouseButtonDown(1))
            {
                Destroy(currentBuilding.gameObject);
                if (manager != null)
                {
                    manager.Refund();
                }
                currentBuilding = null;
            }
        }
        else
        {
            if (Input.GetMouseButtonDown(0))
            {
                // hasPlaced = true;
                RaycastHit hit = new RaycastHit();
                ray = new Ray(new Vector3(p.x, 10, p.z), Vector3.down);
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, buildingsMask))
                {
                    if (placeableBuildingOld != null)
                    {
                        placeableBuildingOld.transform.parent.FindChild("Turret").GetComponent <CannonFireAOE> ().SetPlayerTarget(null);
                        placeableBuildingOld.SetSelected(false);
                    }
                    hit.collider.gameObject.GetComponent <PlaceableBuilding>().SetSelected(true);
                    placeableBuildingOld = hit.collider.gameObject.GetComponent <PlaceableBuilding>();
                }
                else
                {
                    if (placeableBuildingOld != null)
                    {
                        RaycastHit unitHit = new RaycastHit();
                        ray = new Ray(new Vector3(p.x, 10, p.z), Vector3.down);
                        if (Physics.Raycast(ray, out unitHit, Mathf.Infinity, unitMask))
                        {
                            if (unitHit.collider is BoxCollider)
                            {
                                Unit u = unitHit.collider.gameObject.GetComponent <Unit> ();
                                placeableBuildingOld.transform.parent.FindChild("Turret").GetComponent <CannonFireAOE> ().SetPlayerTarget(u);
                            }
                        }
                        else
                        {
                            placeableBuildingOld.transform.parent.FindChild("Turret").GetComponent <CannonFireAOE> ().SetPlayerTarget(null);
                            placeableBuildingOld.SetSelected(false);
//							placeableBuildingOld = null;
                        }
                    }
                }
            }
        }
    }    //Update()
    // Update is called once per frame
    void Update()
    {
        Vector3 m = Input.mousePosition;
        m = new Vector3(m.x, m.y, transform.position.y);
        Vector3 p = camera.ScreenToWorldPoint(m);

        if (currentBuilding != null && !hasPlaced) {
            currentBuilding.position = new Vector3(p.x, 0.2f, p.z);

            if (Input.GetMouseButtonDown(0)) {
                if(IsLeagalPosition() && IsInLot() && !IsInRoad()) {
                    hasPlaced = true;
                    foreach (GameObject go in lots) {
                        Transform[] allChildren = go.GetComponentsInChildren<Transform>();
                        foreach (Transform child in allChildren) {
                            if (child.gameObject.name.Contains("Lot_Placement")) {
                                child.gameObject.renderer.enabled = false;
                            }
                        }
                    }
                    GameManager.currencySys.updatePlyMoney(-buildingPrice);
                    GameManager.isBuilding = false;
                }
            } else if (Input.GetMouseButton(1)) {
                GameManager.isBuilding = false;
                hasPlaced = false;
                foreach (GameObject go in lots) {
                    Transform[] allChildren = go.GetComponentsInChildren<Transform>();
                    foreach (Transform child in allChildren) {
                        if (child.gameObject.name.Contains("Lot_Placement")) {
                            child.gameObject.renderer.enabled = false;
                        }
                    }
                }
                Destroy(currentBuilding.gameObject);
            }
        } else {
            if (Input.GetMouseButtonDown(0)) {
                RaycastHit hit = new RaycastHit();
                Ray ray = new Ray(new Vector3(p.x, 9, p.z), Vector3.down);
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, buildingsMask)) {
                    if(placeableBuildingOld != null) {
                        placeableBuildingOld.SetSelected(false);
                    }
                    hit.collider.gameObject.GetComponent<PlaceableBuilding>().SetSelected(true);
                    placeableBuildingOld = hit.collider.gameObject.GetComponent<PlaceableBuilding>();
                } else {
                    if(placeableBuildingOld != null) {
                        placeableBuildingOld.SetSelected(false);
                    }
                }
            }
        }
    }
 public GameObject SetItem(GameObject b)
 {
     if (currentBuilding != null) {
         Destroy (currentBuilding.gameObject);
         if (manager != null) {
             manager.Refund ();
         }
     }
     hasPlaced = false;
     Debug.Log ("Set Item");
     GameObject res = (GameObject)Instantiate(b);
     currentBuilding = res.transform;
     //		GameObject go = transform.Find ("BuildingFootprint").gameObject;
     //		placeableBuilding = (PlaceableBuilding)go;
     placeableBuilding = currentBuilding.GetComponentsInChildren<PlaceableBuilding>()[0];
     placeableBuilding.SetSelected (true);
     return res;
 }
    // Update is called once per frame
    void Update()
    {
        Camera mainCam = GetComponent<Camera> ();
        Vector3 m = Input.mousePosition;
        //		m = new Vector3(m.x,m.y,transform.position.y);
        //		Vector3 p = mainCam.ScreenToWorldPoint(m);

        Ray ray = mainCam.ScreenPointToRay (m);
        Plane xz = new Plane(Vector3.up, new Vector3(0,0.5f,0));
        float distance;
        xz.Raycast (ray, out distance);
        Vector3 p = ray.GetPoint (distance);

        //		Vector3 p = new Vector3 (0, 0, 0);
        //		Ray ray = mainCam.ScreenPointToRay (m);
        //		if (Physics.Raycast (ray, out hit, Mathf.Infinity, groundMask)) {
        //			m = new Vector3(m.x,m.y,hit.distance);
        //			p = mainCam.ScreenToWorldPoint(m);
        //		}

        if (currentBuilding != null && !hasPlaced) {
            currentBuilding.position = new Vector3(p.x,p.y,p.z);

            if (Input.GetMouseButtonDown (0)) {
                if (IsLegalPosition (p)) {
                    Debug.Log ("Placing Building");
                    hasPlaced = true;
                    //					placeableBuilding.SetSelected (false);
                    placeableBuilding.SetPlaced (true);
                    placeableBuildingOld = placeableBuilding;
                    currentBuilding = null;
                }
            } else if (Input.GetMouseButtonDown (1)) {
                Destroy (currentBuilding.gameObject);
                if (manager != null) {
                    manager.Refund ();
                }
                currentBuilding = null;
            }
        }
        else {
            if (Input.GetMouseButtonDown(0)) {
                // hasPlaced = true;
                RaycastHit hit = new RaycastHit();
                ray = new Ray(new Vector3(p.x,10,p.z), Vector3.down);
                if (Physics.Raycast(ray, out hit,Mathf.Infinity,buildingsMask)) {
                    if (placeableBuildingOld != null) {
                        placeableBuildingOld.transform.parent.FindChild ("Turret").GetComponent<CannonFireAOE> ().SetPlayerTarget (null);
                        placeableBuildingOld.SetSelected(false);
                    }
                    hit.collider.gameObject.GetComponent<PlaceableBuilding>().SetSelected(true);
                    placeableBuildingOld = hit.collider.gameObject.GetComponent<PlaceableBuilding>();
                }
                else {
                    if (placeableBuildingOld != null) {
                        RaycastHit unitHit = new RaycastHit();
                        ray = new Ray(new Vector3(p.x,10,p.z), Vector3.down);
                        if (Physics.Raycast (ray, out unitHit, Mathf.Infinity, unitMask)) {
                            if(unitHit.collider is BoxCollider){
                                Unit u = unitHit.collider.gameObject.GetComponent<Unit> ();
                                placeableBuildingOld.transform.parent.FindChild ("Turret").GetComponent<CannonFireAOE> ().SetPlayerTarget (u);
                            }
                        }else {
                            placeableBuildingOld.transform.parent.FindChild ("Turret").GetComponent<CannonFireAOE> ().SetPlayerTarget (null);
                            placeableBuildingOld.SetSelected(false);
        //							placeableBuildingOld = null;
                        }
                    }
                }
            }
        }
    }