Пример #1
0
    //Handles whether or not the player should pass through the gate and other related changes, such as the color of the gate and the held object.
    public void HandleGate(RaycastHit2D[] hits)
    {
        for (int i = 0; i < hits.Length; i++)
        {
            if (hits[i].collider != null && hits[i].collider.CompareTag("Gate") && manager.CheckEqual(hits[i].collider))
            {
                GameObject gate = manager.GetEqual(hits[i].collider);

                //Case where the player simply passes through with held object if applicable
                if ((gate.GetComponent <GateScript>().Index == 7 && (held == null || (held != null && held.GetComponent <PickupScript>().Index != 7))) || (held != null && held.GetComponent <PickupScript>().Index == 7 && gate.GetComponent <GateScript>().Index == 7 && held.GetComponent <PickupScript>().LastIndex != gate.GetComponent <GateScript>().LastIndex))
                {
                    PassThrough(gate);
                }

                //Case where gate and held object turn white
                else if (held != null && gate.GetComponent <GateScript>().Index == held.GetComponent <PickupScript>().Index&& held.GetComponent <PickupScript>().Index != 7 && gate.GetComponent <GateScript>().Index != 7)
                {
                    gate.GetComponent <GateScript>().Activate();
                    held.GetComponent <PickupScript>().ChangeColor(7);
                    gate.GetComponent <GateScript>().ChangeColor(7);
                    PassThrough(gate);
                    if (gate.GetComponent <GateScript>().ActivateShift)
                    {
                        Shifter.ShiftColors();
                    }
                }

                //Case where gate and held object are white and revert back to previous color.
                else if (held != null && held.GetComponent <PickupScript>().Index == 7 && gate.GetComponent <GateScript>().Index == 7 && held.GetComponent <PickupScript>().LastIndex == gate.GetComponent <GateScript>().LastIndex)
                {
                    PassThrough(gate);
                    if (gate.GetComponent <GateScript>().ActivateShift)
                    {
                        Shifter.ShiftColors();
                    }
                    held.GetComponent <PickupScript>().Revert();
                    gate.GetComponent <GateScript>().Revert();
                    gate.GetComponent <GateScript>().Deactivate();
                }
            }
        }
    }