Пример #1
0
    //Tunneling process: Transports the player across the wall
    private void Tunnel()
    {
        if (collidingWall && collidingWall.GetComponent <WallScript>().energyConsumption < 100)         //If they are touching a wall

        {
            WallScript wallSc       = collidingWall.GetComponent <WallScript>(); // Get the wall script of the wall its touching
            bool       isHorizontal = wallSc.IsHorizontal();                     //check if it's horizontal
            Vector3    target       = transform.position;                        //The position the player will go from tunneling

            if (!isHorizontal)
            {
                if (transform.position.x < collidingWall.transform.position.x)
                {
                    //Debug.Log ("Tunnel Right");
                    target.x = collidingWall.transform.position.x + shiftPosition;                     //Target position is an increased x value
                }
                else
                {
                    //Debug.Log ("Tunnel Left");
                    target.x = collidingWall.transform.position.x - shiftPosition;                     //Target position is an decreased x value
                }
            }
            else
            {
                if (transform.position.y < collidingWall.transform.position.y)
                {
                    //Debug.Log ("Tunnel Up");
                    target.y = collidingWall.transform.position.y + shiftPosition;                     //Target position is an increased y value
                }
                else
                {
                    //Debug.Log ("Tunnel Down");
                    target.y = collidingWall.transform.position.y - shiftPosition;                     //Target position is an decreased y value
                }
            }
            Energy energyScript = GetComponent <Energy>();
            if (energyScript != null)
            {
                energyScript.DecreaseEnergy(wallSc.energyConsumption);
            }
            StartCoroutine("TunnelExec", target);             //Transport the player smoothly
        }
    }