示例#1
0
 private void Update()
 {
     if (!occupied)
     {
         stayFreshTime -= Time.deltaTime;
         if (stayFreshTime < 0)
         {
             //Unregister game object at affordance map
             UIAffordance.UnregisterObject(this.gameObject);
             Destroy(this.gameObject);
         }
     }
 }
示例#2
0
    //Plant seed on it
    void Plant(ASeed seed)
    {
        hasPlants     = true;
        seed.occupied = true;
        seed.MakeStatic();
        seed.transform.parent        = this.transform;
        seed.transform.localPosition = Vector3.zero;

        GetComponent <BoxCollider>().enabled = false;


        StartCoroutine(GrowSeed(seed));

        //Grow seed to a tree
        IEnumerator GrowSeed(ASeed aSeed)
        {
            //Debug.Log("Soil Plant: " + seed.objectType.ToString());

            yield return(new WaitForSeconds(aSeed.growTime));

            //A seed becomes a tree;
            GameObject tree = Instantiate(seed.plantPrefab, this.transform.position, Quaternion.identity);

            tree.transform.parent = this.transform;

            //calculate size
            Vector3 boxSize  = tree.GetComponent <BoxCollider>().size;
            Vector3 soilSize = this.GetComponent <BoxCollider>().size;

            float treeSize = soilSize.x / (boxSize.x + 0.1f);

            tree.transform.localScale = new Vector3(treeSize, treeSize, treeSize);

            //Distroy seed and soil
            UIAffordance.UnregisterObject(aSeed.gameObject);
            Destroy(aSeed.gameObject);
        }
    }
示例#3
0
    //Eat food
    public void Eat(AnimalCharacter animalCharacter)
    {
        animalCharacter.StopMove();

        //Debug.Log("AFood(eat): " + this.objectType.ToString());
        animalCharacter.currentActivity = EActivity.Eat;
        StartCoroutine(EatFood());

        //Eat animation
        animalCharacter.animator.SetInteger("animation", 4);
        IEnumerator EatFood()
        {
            yield return(new WaitForSeconds(this.eatTime));

            animalCharacter.SetIdle();

            //Gain fullness
            animalCharacter.fullness = Mathf.Min(animalCharacter.fullness + fullGain, 1f);

            //Distroy this food
            UIAffordance.UnregisterObject(this.gameObject);
            Destroy(this.gameObject);
        }
    }