示例#1
0
    private void OnTriggerEnter(Collider other)
    {
        //CoinHandler.coins += 1;
        //CoinHandler.updateCoins(CoinHandler.coins);
        CoinHandler CoinHandler = GameObject.Find("DisplayCanvas/CoinScoreSystem").GetComponent(typeof(CoinHandler)) as CoinHandler;

        CoinHandler.updateCoins();
        Destroy(gameObject);
    }
示例#2
0
    // Used by animal behavior scripts to increase hunger points
    public void Eat()
    {
        // Double check that the animal can't be too full.
        if (hungerPoints < maxHungerPoints)
        {
            hungerPoints++;
        }

        // A reward for good game play -> providing food for your animals
        coinHandler.updateCoins(coinsOnEat);
    }
示例#3
0
    // public GameObject collectibleCounterLevel;
    // public GameObject collectibleCounterGameTotal;

    private void OnTriggerEnter(Collider other)
    {
        //  if (GetComponent<Collider>().gameObject.tag == "Player")
        //  {
        //CoinHandler.coins += 1;


        CoinHandler CoinHandler = GameObject.Find("DisplayCanvas/CoinScoreSystem").GetComponent(typeof(CoinHandler)) as CoinHandler;

        CoinHandler.updateCoins();
        Destroy(gameObject);
        //s  }
    }
示例#4
0
    // To be run when GameState is in Place state
    private void Placing()
    {
        // Have a preview of the species to be placed follow the mouse, showing the player where it would be placed
        Ray        ray = mainCamera.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            // Calculate the true bottom of the model with all renderers accounted for.

            float            adjustmentHeight = 0;
            Queue <Renderer> renderers        = new Queue <Renderer>();

            if (placingObjectPreview.GetComponent <Renderer>())
            {
                renderers.Enqueue(placingObjectPreview.GetComponent <Renderer>());
            }

            foreach (var rend in placingObjectPreview.GetComponentsInChildren <Renderer>())
            {
                renderers.Enqueue(rend);
            }

            if (renderers.Count > 0)
            {
                Bounds combinedBounds = renderers.Dequeue().bounds;
                while (renderers.Count > 0)
                {
                    combinedBounds.Encapsulate(renderers.Dequeue().bounds);
                }

                adjustmentHeight = combinedBounds.size.y / 2f;
            }

            // place the object on top of the collider, not halfway through it
            if (!placingObject.GetComponent <PlantBehavior>())
            {
                adjustmentHeight += 1f;
            }

            Vector3 placePoint = new Vector3(hit.point.x, adjustmentHeight, hit.point.z);
            placingObjectPreview.transform.position = placePoint;

            // The object should be spawned when the mouse is clicked, reverting to view mode
            if (Input.GetMouseButton(0))
            {
                if (hit.collider.gameObject.CompareTag("Boundary"))
                {
                    // TODO: Need to alert player this is an unplaceable location
                    Debug.Log("Cannot place on a map boundary!");
                }
                else
                {
                    Destroy(placingObjectPreview);
                    Instantiate <GameObject>(placingObject, placePoint, Quaternion.Euler(0, 0, 0));

                    // Charge the user for buying an animal.
                    coinHandler.updateCoins(-1 * cost);

                    SetState(GameState.View);
                    if (scoreScript.animalScoreValues.ContainsKey(placingObject.tag))
                    {
                        scoreScript.changeScore((int)scoreScript.animalScoreValues[placingObject.tag]);
                    }
                }
            }

            // if user presses escape, revert to view mode
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                Destroy(placingObjectPreview);
                SetState(GameState.View);
            }
        }
    }