コード例 #1
0
    virtual public void Eat(GameObject o)
    {
        if (!o)
        {
            LoseTarget("no obj");
            return;
        }

        NumberInfo ni = o.GetComponent <NumberInfo>();

        if (!ni)
        {
            LoseTarget("no ni");
            return;
        }
        if (ni.usedThisFrame)
        {
            LoseTarget("ni used");
            return;
        }
        ni.usedThisFrame = true;
        ni.NotifyDestroyer(this.gameObject);         // let numberinfo know who is eating it.
        Fraction result = Fraction.Add(this.fraction, ni.fraction);

        if (result.numerator == 0)
        {
            Debug.Log("Result of  animal " + this.fraction + " and ate:" + ni.fraction + " was zero!");
            foreach (IDestroyedByPlayer dp in gameObject.GetComponents(typeof(IDestroyedByPlayer)))
            {
                dp.DestroyedByPlayer();
            }
        }
        base.Eat(ni);
//		Sprite icon = ni.GetComponent<UserEditableObject>().icon;

//		justAteFX.transform.parent = transform;

        if (AnimalIsFrogType())
        {
            float p = Random.Range(0.75f, 1.1f);
            AudioManager.inst.PlayMunch(transform.position, 1, p);           // frogs have a quieter munch
        }
        else
        {
            AudioManager.inst.PlaySheepMunch(transform.position);
        }
        LoseTarget("ate");
    }