dousiyou1058 2014-04-14 22:18
浏览 112
已采纳

检查if语句后,将Unity游戏嵌入到网页中

What I am trying to do is check if the user is logged in so the game could load to play. The page works if I dont check for the login status but the else statement in the code below just displays a white page with nothing on it. The code in the else statement is copied straight from the generated html file from unity. I am new to php and html so I dont really know what changes I would need to make for it to work in my current layout so any help would be very useful. I know the code in the else statement works if its just in a separate html file with no login check.

<div id="main">
<h3>Get started with your website</h3>
<ol class="round">
<li class="one">

    <?php if(!logged_on()) { //This if statement works
        echo '<li><a href="/logon.php">Please login to play</a></li>' . "
";
    }

    else //This doesnt work
    {

         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <title>Unity Web Player | Cool Ninja Platformer</title>
            <script type='text/javascript' src='https://ssl-webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/jquery.min.js'></script>
            <script type="text/javascript">
            <!--
            var unityObjectUrl = "http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject2.js";
            if (document.location.protocol == 'https:')
                unityObjectUrl = unityObjectUrl.replace("http://", "https://ssl-");
            document.write('<script type="text\/javascript" src="' + unityObjectUrl + '"><\/script>');
            -->
            </script>
            <script type="text/javascript">
            <!--
                var config = {
                    width: 960, 
                    height: 600,
                    params: { enableDebugging:"0" }

                };
                config.params["disableContextMenu"] = true;
                var u = new UnityObject2(config);

                jQuery(function() {

                    var $missingScreen = jQuery("#unityPlayer").find(".missing");
                    var $brokenScreen = jQuery("#unityPlayer").find(".broken");
                    $missingScreen.hide();
                    $brokenScreen.hide();

                    u.observeProgress(function (progress) 
                    {
                        switch(progress.pluginStatus) 
                        {
                            case "broken":
                                $brokenScreen.find("a").click(function (e) 
                                {
                                    e.stopPropagation();
                                    e.preventDefault();
                                    u.installPlugin();
                                    return false;
                                });
                                $brokenScreen.show();
                            break;
                            case "missing":
                                $missingScreen.find("a").click(function (e) 
                                {
                                    e.stopPropagation();
                                    e.preventDefault();
                                    u.installPlugin();
                                    return false;
                                });
                                $missingScreen.show();
                            break;
                            case "installed":
                                $missingScreen.remove();
                            break;
                            case "first":
                            break;
                        }
                    });
                    u.initPlugin(jQuery("#unityPlayer")[0], "game.unity3d");
                });
            -->
            </script>
            <style type="text/css">
            <!--
            body {
                font-family: Helvetica, Verdana, Arial, sans-serif;
                background-color: white;
                color: black;
                text-align: center;
            }
            a:link, a:visited {
                color: #000;
            }
            a:active, a:hover {
                color: #666;
            }
            p.header {
                font-size: small;
            }
            p.header span {
                font-weight: bold;
            }
            p.footer {
                font-size: x-small;
            }
            div.content {
                margin: auto;
                width: 960px;
            }
            div.broken,
            div.missing {
                margin: auto;
                position: relative;
                top: 50%;
                width: 193px;
            }
            div.broken a,
            div.missing a {
                height: 63px;
                position: relative;
                top: -31px;
            }
            div.broken img,
            div.missing img {
                border-width: 0px;
            }
            div.broken {
                display: none;
            }
            div#unityPlayer {
                cursor: default;
                height: 600px;
                width: 960px;
            }
            -->
            </style>
        </head>
        <body>
            <p class="header"><span>Unity Web Player | </span>Cool Ninja Platformer</p>
            <div class="content">
                <div id="unityPlayer">
                    <div class="missing">
                        <a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now!">
                            <img alt="Unity Web Player. Install now!" src="http://webplayer.unity3d.com/installation/getunity.png" width="193" height="63" />
                        </a>
                    </div>
                </div>
            </div>
            <p class="footer">&laquo; created with <a href="http://unity3d.com/unity/" title="Go to unity3d.com">Unity</a> &raquo;</p>
        </body>
    </html>
    }

    ?>

</li>
</ol>
</div>
  • 写回答

2条回答 默认 最新

  • dsyo9700 2014-04-14 22:24
    关注

    Before trying to print explicit HTML without using echo you have to close your php code block with ?>. And before doing more php code you have to open it again <?php.

    Another issue is that you need <!DOCTYPE html... to be the first line of your page. So having <div id="main"> and so on above it is going to cause a big problem. So put that at the top always.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <?php 
    if(!logged_on()) 
    { 
        echo '<li><a href="/logon.php">Please login to play</a></li>' . "
    ";
    }
    else 
    {
    ?>
        <head>
        all whatever html you want to have explit
    <?php
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站