Ejemplo n.º 1
0
Archivo: UI.cs Proyecto: dongchenyu/3D-
 void Update()
 {
     if (queryInt.getRound() <= 3)
     {
         userInt.emitDisk();
         if (queryInt.isShooting())
         {
             winText.text = "";
         }
         if (queryInt.isShooting() && Input.GetMouseButtonDown(0) && Time.time > nextFireTime)
         {
             nextFireTime = Time.time + fireRate;
             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             bullet.GetComponent <Rigidbody>().velocity = Vector3.zero;
             bullet.GetComponent <Rigidbody>().position = transform.position;
             bullet.GetComponent <Rigidbody>().AddForce(ray.direction * speed, ForceMode.Impulse);
             RaycastHit hit;
             if (Physics.Raycast(ray, out hit) && hit.collider.gameObject.tag == "disk")
             {
                 hit.collider.gameObject.SetActive(false);
             }
         }
     }
     else
     {
         winText.text = "You Win";
     }
     roundText.text = "Round: " + queryInt.getRound().ToString();
     scoreText.text = "Score: " + queryInt.getPoint().ToString();
     if (round != queryInt.getRound())
     {
         round        = queryInt.getRound();
         winText.text = "Round " + round.ToString();
     }
 }
Ejemplo n.º 2
0
    void Update()
    {
        if (queryInt.isCounting())
        {
            // 显示倒计时
            mainText.text = queryInt.getEmitTime().ToString();
        }
        else
        {
            if (Input.GetKeyDown("space"))
            {
                userInt.emitDisk();     // 发射飞碟
            }
            if (queryInt.isShooting())
            {
                mainText.text = "";     // 射击开始,隐藏主提示
            }
            // 发射子弹
            if (queryInt.isShooting() && Input.GetMouseButtonDown(0) && Time.time > nextFireTime)
            {
                nextFireTime = Time.time + fireRate;

                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);    // 摄像机到鼠标射线
                bullet.GetComponent <Rigidbody>().velocity = Vector3.zero;      // 子弹刚体速度重置
                bullet.transform.position = transform.position;                 // 子弹从摄像机位置射出
                bullet.GetComponent <Rigidbody>().AddForce(ray.direction * speed, ForceMode.Impulse);

                RaycastHit hit;
                if (Physics.Raycast(ray, out hit) && hit.collider.gameObject.tag == "Disk")
                {
                    // 播放爆炸粒子特效
                    explosion.transform.position = hit.collider.gameObject.transform.position;
                    explosion.GetComponent <Renderer>().material.color = hit.collider.gameObject.GetComponent <Renderer>().material.color;
                    explosion.Play();
                    // 击中飞碟设置为不活跃,自动回收
                    hit.collider.gameObject.SetActive(false);
                }
            }
        }
        roundText.text = "Round: " + queryInt.getRound().ToString();
        scoreText.text = "Score: " + queryInt.getPoint().ToString();
        // 如果回合更新,主提示显示新回合
        if (round != queryInt.getRound())
        {
            round         = queryInt.getRound();
            mainText.text = "Round " + round.ToString() + " !";
        }
    }
Ejemplo n.º 3
0
 void Update()
 {
     if (queryInt.isCounting())
     {
         maintips.text = ((int)queryInt.getEmitTime()).ToString();                // 显示游戏的倒计时
     }
     else
     {
         if (Input.GetKeyDown("space"))
         {
             userInt.emitDisk();                     // 有监测到空格按下就发射飞碟
         }
         if (queryInt.isShooting())
         {
             maintips.text = "";                     // 一旦开始射击了,表明游戏开始,隐藏游戏提示
         }
         if (gamestate == false)
         {
             userInt.diskMove();
         }
         if (queryInt.isShooting() && Input.GetMouseButtonDown(0) && Time.time > nextBulletTime)
         {
             // 发射子弹
             nextBulletTime = Time.time + bulletInterval;
             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);                  // 由摄像机发出,方向为摄像机到鼠标点击位置的连线
             bullet.GetComponent <Rigidbody>().velocity = Vector3.zero;                    // 速度重置
             bullet.transform.position = transform.position;                               // 子弹从摄像机的位置射出
             bullet.GetComponent <Rigidbody>().AddForce(bulletSpeed * ray.direction, ForceMode.Impulse);
             RaycastHit hit;
             if (Physics.Raycast(ray, out hit) && hit.collider.gameObject.tag == "Disk")
             {
                 // 击中飞碟设置为不活跃,自动回收
                 hit.collider.gameObject.SetActive(false);
             }
         }
     }
     roundText.text  = "Round: " + queryInt.getRound().ToString();          // 通过查询接口查询关卡数
     scoresText.text = "Scores: " + queryInt.getScores().ToString();        // 通过查询接口查询当前分数
     if (roundnow != queryInt.getRound())
     {
         // 如果关卡数更新要在mainTips里面进行提示
         roundnow      = queryInt.getRound();
         maintips.text = "Round: " + roundnow.ToString() + " ! ";
     }
 }
Ejemplo n.º 4
0
    void Update()
    {
        if (queryInt.isCounting())
        {
            mainText.text = ((int)queryInt.getEmitTime()).ToString();
        }
        else
        {
            if (Input.GetKeyDown("space"))
            {
                userInt.emitDisk();
            }
            if (queryInt.isShooting())
            {
                mainText.text = "";
            }

            if (queryInt.isShooting() && Input.GetMouseButtonDown(0) && Time
                .time > nextFireTime)
            {
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                bullet.GetComponent <Rigidbody>().velocity = Vector3.zero;
                bullet.transform.position = transform.position;
                bullet.GetComponent <Rigidbody>().AddForce(ray.direction * speed, ForceMode.Impulse);

                RaycastHit hit;
                if (Physics.Raycast(ray, out hit) && hit.collider.gameObject.tag == "Disk")
                {
                    explosion.transform.position = transform.position;
                    explosion.GetComponent <Renderer>().material = hit.collider.gameObject.GetComponent <Renderer>().material;
                    explosion.GetComponent <ParticleSystem> ().Play();
                    hit.collider.gameObject.SetActive(false);
                }
            }
        }
        roundText.text = "ROUND: " + queryInt.getRound().ToString();
        scoreText.text = "SCORE: " + queryInt.getPoint().ToString();
        if (round != queryInt.getRound())
        {
            round         = queryInt.getRound();
            mainText.text = "ROUND " + round.ToString() + "!";
        }
    }
Ejemplo n.º 5
0
 void Update()
 {
     if (Input.GetKeyDown("space"))
     {
         userInt.emitDisk();
     }
     if (queryInt.isShooting())
     {
         mainText.text = "";
     }
     if (queryInt.isShooting() && Input.GetMouseButtonDown(0))
     {
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         bullet.GetComponent <Rigidbody>().velocity = Vector3.zero;
         bullet.transform.position = transform.position;
         bullet.GetComponent <Rigidbody>().AddForce(
             ray.direction * speed, ForceMode.Impulse);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit) &&
             hit.collider.gameObject.tag == "Disk")
         {
             explosion.transform.position = hit.collider.gameObject.transform.position;
             explosion.GetComponent <Renderer>().material.color =
                 hit.collider.gameObject.GetComponent <Renderer>().material.color;
             explosion.Play();
             hit.collider.gameObject.SetActive(false);
         }
     }
     roundText.text = "Round: " + queryInt.getRound().ToString();
     scoreText.text = "Score: " + queryInt.getPoint().ToString();
     if (round != queryInt.getRound())
     {
         round         = queryInt.getRound();
         mainText.text = "空格键发射";
     }
 }