Example #1
0
    private void OnTriggerStay(Collider other)
    {
        Conduction otherObjectConduction = other.GetComponentInParent <Conduction>();

        if (otherObjectConduction)
        {
            voltageReading    = otherObjectConduction.voltage;
            currentReading    = otherObjectConduction.current;
            resistanceReading = otherObjectConduction.resistance;
            isConnected       = true;
        }
    }
Example #2
0
    private void OnTriggerStay(Collider other)
    {
        Conduction otherObjectConduction = other.GetComponent <Conduction>();

        if (otherObjectConduction)
        {
            if (terminal == "Power_Source_Positive" && otherObjectConduction.loopIsClosed)
            {
            }
            if (terminal == "Power_Source_Negative" && otherObjectConduction.loopIsClosed && circuitResistanceTotal == 0f)
            {
                circuitResistanceTotal = otherObjectConduction.resistance;
            }
        }
    }
    /*
     * The circuit is connnected. Initialize the variables.
     */
    private void ClosedLoopRoutine(Collider other)
    {
        if (positivePassThrough == true && negativePassThrough == true)
        {
            loopIsClosed = true;
        }
        // instance of GameObject that is being collided with
        GameObject otherObject = other.gameObject;

        // Red wire must touch positive side of power source
        if (otherObject.tag == "Power_Source_Positive" && positiveNumberInSeries == 0)
        {
            positivePassThrough     = true;
            positiveNumberInSeries += 1;

            voltage = otherObject.GetComponent <PowerSource>().getPowerSourceVoltage();
        }
        // Black wire must touch negative side of power source
        if (otherObject.tag == "Power_Source_Negative" && negativeNumberInSeries == 0)
        {
            negativePassThrough     = true;
            negativeNumberInSeries += 1;
        }

        if (otherObject.tag == "Power_Source_Negative" && current == 0)
        {
            current = otherObject.GetComponent <PowerSource>().getCurrent();
            //Debug.Log("getting battery current");
        }
        // instance of conduction property of "other" object
        Conduction otherObjectConduction = otherObject.GetComponent <Conduction>();

        if (otherObjectConduction)
        {
            if (positiveNumberInSeries > otherObjectConduction.positiveNumberInSeries)
            {
                if (otherObjectConduction.voltage != 0 && voltage == 0)
                {
                    voltage = otherObjectConduction.voltage;
                }
                if (otherObjectConduction.resistance != 0 && resistance == 0)
                {
                    resistance = otherObjectConduction.resistance + localResistance;
                    //Debug.Log("getting resistance from resistor");
                }
                if (otherObjectConduction.resistance == 0 && resistance == 0 && localResistance != 0)
                {
                    resistance = localResistance;
                    //Debug.Log("Setting local resistance");
                }
            }

            if (negativeNumberInSeries > otherObjectConduction.negativeNumberInSeries)
            {
                if (otherObjectConduction.current != 0 && current == 0)
                {
                    current = otherObjectConduction.current;
                }
            }

            //Negative Check
            if (otherObjectConduction.negativePassThrough == true && negativePassThrough == false)
            {
                negativePassThrough = true;
                if (negativeNumberInSeries == 0 && otherObjectConduction.negativeNumberInSeries != 0)
                {
                    negativeNumberInSeries = otherObjectConduction.negativeNumberInSeries + 1;
                }
            }

            //Positive Check
            if (otherObjectConduction.positivePassThrough == true && positivePassThrough == false)
            {
                positivePassThrough = true;
                if (positiveNumberInSeries == 0 && otherObjectConduction.positiveNumberInSeries != 0)
                {
                    positiveNumberInSeries = otherObjectConduction.positiveNumberInSeries + 1;
                }
            }
        }
    }