public void setPaddock(Paddock setPaddock)
 {
     paddock   = setPaddock;
     Pprofiles = paddock.GetComponentInChildren <PaddockProfiles>();
 }
Exemplo n.º 2
0
    private void Update()
    {
        // Check to see if the player has clicked a tile and if they have, try to find a path to that
        // tile. If we find a path then the character will move along it to the clicked tile.
        Ray screenClick = MainCamera.ScreenPointToRay(Input.mousePosition);
        int hits        = Physics.RaycastNonAlloc(screenClick, mRaycastHits);

        //If the ray cast hits anything
        if (hits > 0)
        {
            //Grab the first ray cast hit and assign the tile to that transform
            tile = mRaycastHits[0].transform.GetComponent <EnvironmentTile>();

            //Only update when asked to (bool)
            if (placingPaddock)
            {
                paddockStandIn.SetActive(true);
                placePaddockUpdate(tile, getPaddockSize());
            }
            else if (placingDog)
            {
                placeDog(tile);
            }
            else if (removingDebris)
            {
                actionSprite.SetActive(true);
                actionSprite.GetComponent <Image>().sprite = remove;
                actionSprite.transform.position            = new Vector3(Input.mousePosition.x, Input.mousePosition.y + 20, Input.mousePosition.z);
                clearDebris(tile);
            }
            else if (placingPaths)
            {
                actionSprite.SetActive(true);
                actionSprite.GetComponent <Image>().sprite = hammer;
                actionSprite.transform.position            = new Vector3(Input.mousePosition.x, Input.mousePosition.y + 20, Input.mousePosition.z);
                placePathways(tile);
            }
            else if (placingShops)
            {
                burgerShop.SetActive(true);
                placeShopUpdate(tile);
            }
            else if (placingFood)
            {
                actionSprite.SetActive(true);
                actionSprite.GetComponent <Image>().sprite = foodSprite;
                actionSprite.transform.position            = new Vector3(Input.mousePosition.x, Input.mousePosition.y + 20, Input.mousePosition.z);
            }
            else if (placingDeco)
            {
                if (tile == null)
                {
                    tile = mRaycastHits[1].transform.GetComponent <EnvironmentTile>();
                }
                placeDecoUpdate(tile);
            }

            //Unselect all buttons
            //Right mouse click
            //For stopping current action
            if (Input.GetMouseButtonDown(1))
            {
                //Clear up any objects and variables within the scene
                placingDog     = false;
                placingPaths   = false;
                removingDebris = false;
                placingShops   = false;
                placingFood    = false;
                placingDeco    = false;

                //Stand in
                profile.transform.localPosition        = new Vector3(0, 300, 0);
                paddockProfile.transform.localPosition = new Vector3(0, 300, 0);

                //Sprite
                actionSprite.SetActive(false);

                if (spawnedDog != null)
                {
                    Destroy(spawnedDog);
                }

                if (spawnedDeco != null)
                {
                    Destroy(spawnedDeco);
                }

                if (placingPaddock)
                {
                    Destroy(paddockStandIn);
                    placingPaddock = false;
                }

                Destroy(burgerStandIn);
            }

            if (!inMenu && !doingAction())
            {
                if (Physics.Raycast(screenClick, out mRaycastHits[0]))
                {
                    //If the raycast is hitting a dog, and not just placing one
                    if (mRaycastHits[0].transform.tag == "Dog" && !placingDog)
                    {
                        //Get the script and assign it to a gameobject
                        profiles = mRaycastHits[0].transform.GetComponentInChildren <DogProfile>();

                        //Makes sure profiles has been initiated first before calling functions
                        if (profiles != null && !inMenu)
                        {
                            profiles.showProfile();
                            showDogProfile();
                        }
                    }
                    else
                    {
                        //Stand in
                        profile.transform.localPosition = new Vector3(0, 300, 0);
                    }


                    //If the raycast is hitting a dog, and not just placing one
                    if (mRaycastHits[0].transform.tag == "Paddock" && !doingAction())
                    {
                        if (Input.GetMouseButtonDown(0))
                        {
                            if (placingFood)
                            {
                                if (currency.sufficientFunds(foodCost))
                                {
                                    interactingPaddock = mRaycastHits[0].transform.GetComponentInParent <Paddock>().getPaddock();
                                    placeFood(interactingPaddock);
                                    actionSprite.SetActive(false);

                                    currency.takeIncome(foodCost);
                                }
                            }
                        }

                        //If on the specific part of the paddock
                        if (!placingFood && !inMenu)
                        {
                            PProfiles = mRaycastHits[0].transform.GetComponentInParent <PaddockProfiles>();
                            PProfiles.showProfile();
                            showPaddockProfile();
                        }
                    }
                    else
                    {
                        paddockProfile.transform.localPosition = new Vector3(0, 300, 0);
                    }


                    if (mRaycastHits[0].transform.name == "Hooligan(Clone)" && eventActive)
                    {
                        if (Input.GetMouseButtonDown(0))
                        {
                            events.releaseTheDogs();
                            eventActive = false;
                        }
                    }
                }
            }
        }
    }