Exemplo n.º 1
0
    void tryTakingToy()
    {
        GameObject[] toys = GameObject.FindGameObjectsWithTag("toy");
        carriedToy = null;
        float minDistance = 0;

        foreach (GameObject toy in toys)
        {
            float distance = Mathf.Sqrt(Mathf.Pow(gameObject.transform.position.x - toy.gameObject.transform.position.x, 2) + Mathf.Pow(gameObject.transform.position.y - toy.gameObject.transform.position.y, 2));
            if (carriedToy == null || distance < minDistance)
            {
                minDistance = distance;
                carriedToy  = toy;
            }
        }
        Debug.Log(carriedToy);
        if (carriedToy != null && !takingObject)
        {
            ToyBehaviour toyBehaviour = carriedToy.GetComponent <ToyBehaviour>();
            toyBehaviour.displayInfoEnabled = false;
            if (toyBehaviour.playerInReach > 0)
            {
                toyBehaviour.takenByPlayer = true;

                takingObject = true;
            }
            else
            {
                carriedToy = null;
            }
        }
    }
Exemplo n.º 2
0
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.collider.CompareTag("Toy"))
     {
         ToyBehaviour toy = collision.collider.GetComponent <ToyBehaviour>();
         if (toy)
         {
             ImTouchingThisToy = new System.WeakReference <ToyBehaviour>(toy);
         }
     }
 }
Exemplo n.º 3
0
 void Update()
 {
     FoodEatingCooldown = Mathf.Max(0.0f, FoodEatingCooldown - Time.deltaTime);
     BarkCooldown       = Mathf.Max(0.0f, BarkCooldown - Time.deltaTime);
     if (SleepyTime > 0.0f)
     {
         float noiseLevel = 0.0f;
         if (noiseLevel > 0.2f)
         {
             // wake up grumpy and go somewhere else quieter つ´Д`)つ
             internalState = "つ´Д`)つ";
             BarkGrumpy();
         }
         else
         {
             // sleepy time ( ु⁎ᴗ_ᴗ⁎)ु.。zZ
             internalState   = "( ु⁎ᴗ_ᴗ⁎)ु.。zZ";
             agent.isStopped = true;
             Energy         += Time.deltaTime * SleepRecovery;
             SleepyTime     -= Time.deltaTime;
         }
     }
     else if (Energy < 0.1f)
     {
         SleepyTime = Mathf.Min(1.0f, SleepyTime + 1.0f);
     }
     else if (Hunger > 0.5f)
     {
         GameObject iWantThisFood = null;
         if (IWantThisFood != null && IWantThisFood.TryGetTarget(out iWantThisFood))
         {
             // walk towards food
             FoodBehaviour imTouchingThisFood = null;
             if (ImTouchingThisFood != null && ImTouchingThisFood.TryGetTarget(out imTouchingThisFood))
             {
                 // yum yum ლ(´ڡ`ლ)
                 internalState = "ლ(´ڡ`ლ)";
                 EatFood(imTouchingThisFood);
                 IWantThisFood      = null;
                 ImTouchingThisFood = null;
             }
             else
             {
                 // go walk towards food ԅ(♡﹃♡ԅ)
                 internalState = "ԅ(♡﹃♡ԅ)";
                 UpdateTarget(iWantThisFood.transform.position, 1.0f);
             }
         }
         else
         {
             System.WeakReference <GameObject> foodObject = SceneManager.GetClosestNonEmptyFood(transform.position);
             if (foodObject.TryGetTarget(out iWantThisFood))
             {
                 IWantThisFood = foodObject;
             }
             else
             {
                 // whaaaa? no food around Щ(º̩̩́Дº̩̩̀щ)
                 internalState = "Щ(º̩̩́Дº̩̩̀щ)";
                 // sulk and bark a bit
                 BarkSad();
             }
         }
     }
     else
     {
         // go play!
         internalState = "(^ω^)";
         Energy       -= Time.deltaTime * EnergySpendingPlaying;
         Hunger       += Time.deltaTime * HungerRate;
         ToyBoredom   += Time.deltaTime * ToyBoredomRate;
         if (ToyBoredom >= 1.0f)
         {
             IWantThisToy = null;
             ToyBoredom   = 0.0f;
         }
         GameObject iWantThisToy = null;
         if (IWantThisToy != null && IWantThisToy.TryGetTarget(out iWantThisToy))
         {
             UpdateTarget(iWantThisToy.transform.position, 2.0f);
             BarkHappy();
             ToyBehaviour toy = null;
             if (ImTouchingThisToy != null && ImTouchingThisToy.TryGetTarget(out toy))
             {
                 toy.ShootUpRandomDirection();
                 ImTouchingThisToy = null;
             }
         }
         else
         {
             System.WeakReference <GameObject> toyObject = SceneManager.GetRandomToy();
             if (toyObject.TryGetTarget(out iWantThisToy))
             {
                 IWantThisToy = toyObject;
             }
             else
             {
             }
         }
     }
 }