Example #1
0
    void Awake()
    {
        batterBallQuantity = GetComponent <Batter_quantity>();
        trailRenderer      = GetComponent <TrailRenderer>();

        batterBallQuantity.OnBatterChanged += OnBatterChanged;
    }
    private void OnPanHit( )
    {
        // check that we have reached the pan.
        // the length of the raycast can be longer than the travel distance.
        if (NextPosition.y > rayHit.point.y)
        {
            return;
        }

        // correct it position, turn off gravity and the raycast since we have now reached the pan, and we wont be colliding with anythink else.
        updating = false;
        GetComponent <Rigidbody>().useGravity = false;
        GetComponent <Rigidbody>().velocity   = Vector3.zero;
        transform.position = rayHit.point;


        //Attamp to find the fryingPan Pancake class, it has to search its parents since the collider is nested into the object.
        FryingPan_pancake panPancake = rayHit.transform.GetComponentInParent <FryingPan_pancake>();

        if (panPancake == null)
        {
            return;
        }

        // Get batter qt of the batterBall and apply it to a mixture pancake.
        Batter_quantity quantity = GetComponent <Batter_quantity>();

        panPancake.AddBatter(quantity.GetBatterQuantity(), rayHit.point);
        transform.position = rayHit.point;
    }
    void Awake()
    {
        GetComponent <Pancake_state>().OnStateChanged += OnPancakeStateChanged;
        batterQuantity = GetComponent <Batter_quantity>();
        batterQuantity.OnBatterChanged += OnBatterChanged;

        lerpTimer.SetTimer(lerpIntervals, true);

        //NOTE: just for now.
        // I WILL NOT be using scale but just to get it working.
        // insted i should move the bones/joints of the pnacake.
        // (cuz pancakes have bones now :D)
        transform.localScale = startLerpScale = targetScale = Vector3.zero;
        volume = batterQuantity.GetBatterQuantity() / quantityToVolumRatio;
    }
    protected override void Update()
    {
        base.Update();

        if (!active)
        {
            return;
        }

        if (inputValue.ClampedPrecent == 1f)            //hmm this -1 ant good. it it cuz the min value is the max, but its not a grantee
        {
            if (currentBatterBall != null)
            {
                currentBatterBall.SendMessage("OnBatterRelease");
                currentBatterBall = null;
            }

            return;
        }

        float spwanInterval = (1f / spwanFrequency.GetValue(1f - inputValue.ClampedPrecent));

        if (Time.time >= nextSpwanTime)                 // spwan a new batter ball
        {
            // Let the current ball know its being released from the jug.
            if (currentBatterBall != null)
            {
                currentBatterBall.SendMessage("OnBatterRelease");
            }

            currentBatterBall = Instantiate(batterBallPrefab, minSpwanLocation.position, Quaternion.identity);
            lastSpwanTime     = Time.time;

            // set batter ball trails lifetime :)
            float batterTrailLife = spwanInterval < batterBall_trail_minLife ? batterBall_trail_minLife : spwanInterval;
            currentBatterBall.SendMessage("SetTime", batterTrailLife);
        }
        else if (currentBatterBall != null)             //move the batter closer to the edge of the jug.
        {
            currentBatterBall.transform.position = Vector3.Lerp(minSpwanLocation.position, maxSpwanLocation.position, 1f - (nextSpwanTime - Time.time) / spwanInterval);

            float remainingBatter = currentBatterBall.AddBatter(jugBatterQuantity.UseBatter(maxPourRate * (1f - inputValue.ClampedPrecent) * Time.deltaTime));
            jugBatterQuantity.AddBatter(remainingBatter);               // return any batter that could not be added to the ball back to the jug :P
        }

        nextSpwanTime = lastSpwanTime + spwanInterval;
    }
    }                                                                   // NOTE: it might be better if this was set by Pancake scale, but i want to play factorio, so this will do for now.

    private void Awake()
    {
        batterQuantity = GetComponent <Batter_quantity>();
    }