예제 #1
0
        private void InstantiateNewObject(Waypoint waypoint)
        {
            if (!waypoint.isPlaceable)
            {
                Debug.Log("Waypoint: " + waypoint + " is not placeable");
                return;
            }
            PlaceableObject newPlaceableObject = Instantiate(placeableObject, waypoint.transform.position, Quaternion.identity);

            newPlaceableObject.transform.parent = transform;
            newPlaceableObject.SetWaypoint(waypoint);
            factoryQueue.Enqueue(newPlaceableObject);
            waypoint.isPlaceable = false;
            newPlaceableObject.GetComponent <Collider>().enabled = true;
            //waypoint.isRoad = true;

            objectManager.placeableObjects.Add(newPlaceableObject.transform);
            if (newPlaceableObject.GetComponent <Factory>())
            {
                objectManager.factories.Add(newPlaceableObject);
            }
            if (newPlaceableObject.GetComponent <HomeBase>())
            {
                objectManager.factories.Add(newPlaceableObject);
                newPlaceableObject.GetComponent <HomeBase>().isHomebase = true;
                LevelManager.Instance.SetState(State.Game);
                FindObjectOfType <GameUIHandler>().SetButtonsDefaultColor();
                SetActivePlaceableObject(null);
            }
            if (newPlaceableObject.GetComponent <Blocker>())
            {
                objectManager.blockers.Add(newPlaceableObject.transform);
            }
        }
예제 #2
0
        private void Start()
        {
            score         = FindObjectOfType <Score>();
            objectManager = FindObjectOfType <ObjectManager>();
            float cost = placeableObjectPrefab.GetComponent <PlaceableObject>().GetCost();

            priceText.text = Mathf.RoundToInt(cost).ToString() + "$";
        }
예제 #3
0
        public void AddPlaceableObject(Waypoint waypoint)
        {
            if (placeableObject == null)
            {
                return;
            }

            if (!waypoint.isPlaceable)
            {
                return;
            }

            if (placeableObject.GetCost() > score.GetTotalScore())
            {
                SetActivePlaceableObject(null);
                Debug.Log("Not enough points!");
                return;
            }

            if (placeableObject.GetComponent <Blocker>() && objectManager.blockers.Count >= objectManager.maxBlockers)
            {
                Debug.Log("Can't add more blockers");
                return;
            }

            if (placeableObject.canSpawnOnRoads && !waypoint.isRoad)
            {
                Debug.Log(placeableObject.name + ": Can't place here: " + waypoint.name);
                return;
            }
            else if (!placeableObject.canSpawnOnRoads && waypoint.isRoad)
            {
                Debug.Log(placeableObject.name + ": Can't place here: " + waypoint.name);
                return;
            }

            else if (placeableObject.canSpawnOnRoads && waypoint.isRoad)
            {
                FindObjectOfType <Score>().DecreasePoints(placeableObject.GetCost());
                InstantiateNewObject(waypoint);
                return;
            }

            else
            {
                FindObjectOfType <Score>().DecreasePoints(placeableObject.GetCost());
                InstantiateNewObject(waypoint);
                if (hoverPlaceableObject != null)
                {
                    Destroy(hoverPlaceableObject.gameObject);
                    hoverPlaceableObject = null;
                }
            }
        }
예제 #4
0
    // Update is called once per frame
    void Update()
    {
        Rect screenRect = new Rect(0, 0, Screen.width, Screen.height);

        if (screenRect.Contains(Input.mousePosition) && currentObject != null)
        {
            //Returns a ray going from camera through a screen point.
            //Input.mousePosition gives us our current mouse position in pixel coordinates
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            //This object will allow us to get information on the collider our ray hits.
            RaycastHit hit;

            //This if statement will only execute if the raycast hits into something
            if (Physics.Raycast(ray, out hit))
            {
                //If our mouse is over a platform
                if (hit.collider.tag == "Platform")
                {
                    if (!placed)
                    {
                        currentObject.transform.position = hit.point;
                    }

                    if (Input.GetMouseButtonDown(0))
                    {
                        placed = true;
                        currentObject.GetComponent <PlaceableObject>().isPlaced = true;
                    }

                    if (Input.GetMouseButtonUp(0))
                    {
                        GameState.Instance.windmillAmount++;
                        currentObject = null;
                        placed        = false;
                    }
                }
            }
        }
    }
예제 #5
0
        public void HoverPlaceableObject(Waypoint waypoint)
        {
            if (placeableObject == null)
            {
                return;
            }

            if (!waypoint.isPlaceable)
            {
                return;
            }

            if (placeableObject.GetCost() > score.GetTotalScore())
            {
                SetActivePlaceableObject(null);
                return;
            }

            if (placeableObject.GetComponent <Blocker>() && objectManager.blockers.Count >= objectManager.maxBlockers)
            {
                return;
            }

            if (placeableObject.canSpawnOnRoads && waypoint.isRoad)
            {
                if (hoverPlaceableObject == null)
                {
                    hoverPlaceableObject = Instantiate(placeableObject, waypoint.transform.position, Quaternion.identity);
                    ChangeHoverColor();
                    hoverPlaceableObject.actionsEnabled = false;
                    hoverPlaceableObject.GetComponent <Collider>().enabled = false;
                }

                else
                {
                    hoverPlaceableObject.GetComponent <Collider>().enabled = false;
                    hoverPlaceableObject.transform.position = waypoint.transform.position;
                }
            }



            if (!waypoint.isPlaceable)
            {
                return;
            }
            else if (placeableObject.canSpawnOnRoads && !waypoint.isRoad)
            {
                return;
            }
            else
            {
                if (waypoint.isRoad)
                {
                    return;
                }
                if (hoverPlaceableObject == null)
                {
                    hoverPlaceableObject = Instantiate(placeableObject, waypoint.transform.position, Quaternion.identity);
                    ChangeHoverColor();
                    hoverPlaceableObject.actionsEnabled = false;
                    hoverPlaceableObject.GetComponent <Collider>().enabled = false;
                }

                else
                {
                    hoverPlaceableObject.GetComponent <Collider>().enabled = false;
                    hoverPlaceableObject.transform.position = waypoint.transform.position;
                }
            }
        }