public void Judge()
    {
        if (shootAtSth != null && shootAtSth.transform.tag == "Disk" && shootAtSth.activeInHierarchy)
        {
            scoreRecorder.Record(shootAtSth);
            diskFactory.FreeDisk(shootAtSth);
            shootAtSth = null;
        }

        if (scoreRecorder.getScore() >= 1000)
        {
            StopAllCoroutines();
            state = State.WIN;
        }

        else if (leaveSeconds == 0)
        {
            StopAllCoroutines();
            state = State.LOSE;
        }
        else
        {
            state = State.CONTINUE;
        }
    }
Beispiel #2
0
    private int collisionNum; //用于限制碰撞检测的次数,初始化为1,只处理最先的碰撞

    void OnCollisionEnter(Collision collision)
    {
        if (collisionNum <= 0)
        {
            return;                   //已碰撞过一次
        }
        if (!collision.collider.gameObject.name.Contains("ring"))
        {
            return;                                                      //撞到其他箭不处理
        }
        //确认撞到的是哪一环
        Debug.Log(collision.collider.gameObject.name + " is hitted by " + collision.gameObject.name);
        //记录分数
        scoreRecorder.Record(collision);
        //撞到之后箭头隐藏
        head.SetActive(false);
        // 取消箭身的刚体,让箭留在靶上
        Rigidbody rigidbody = this.gameObject.GetComponent <Rigidbody>();

        rigidbody.velocity = Vector3.zero;
        Destroy(rigidbody);
        //Destroy(body.GetComponent<Collider>());

        //最先碰到的靶,减一
        collisionNum--;
    }
Beispiel #3
0
  public void Hit(Vector3 pos)
  {
      Ray ray = Camera.main.ScreenPointToRay(pos);

      RaycastHit[] hits;
      hits = Physics.RaycastAll(ray);
      bool beHit = false;

      for (int i = 0; i < hits.Length; i++)
      {
          RaycastHit hit = hits[i];
          if (hit.collider.gameObject.GetComponent <DiskData>() != null)
          {
              for (int j = 0; j < notBeShoted.Count; j++)
              {
                  if (hit.collider.gameObject.GetInstanceID() == notBeShoted[j].gameObject.GetInstanceID())
                  {
                      beHit = true;
                  }
              }
              if (!beHit)
              {
                  return;
              }
              notBeShoted.Remove(hit.collider.gameObject);
              scoreRecorder.Record(hit.collider.gameObject);

              diskFactory.FreeDisk(hit.collider.gameObject);
              break;
          }
      }
  }
Beispiel #4
0
    public void Click(Vector3 pos)
    {
        Ray ray = Camera.main.ScreenPointToRay(pos);

        RaycastHit[] hits;
        hits = Physics.RaycastAll(ray);
        for (int i = 0; i < hits.Length; i++)
        {
            RaycastHit hit = hits[i];

            if (hit.collider.gameObject.GetComponent <DiskData>() != null)
            {
                for (int j = 0; j < freeDisk.Count; j++)
                {
                    if (hit.collider.gameObject.GetInstanceID() == freeDisk[j].gameObject.GetInstanceID())
                    {
                        scoreRecorder.Record(hit.collider.gameObject);
                        StartCoroutine(WaitingParticle(0.08f, hit, diskFactory, hit.collider.gameObject));
                        freeDisk.Remove(freeDisk[j]);
                        break;
                    }
                }
            }
        }
    }
Beispiel #5
0
    public void Judge()                                                                               //判断游戏状态,是否射中以及够不够分数进入下一回合
    {
        if (shootAtSth != null && shootAtSth.transform.tag == "Disk" && shootAtSth.activeInHierarchy) //射中飞碟
        {
            scoreRecorder.Record(shootAtSth);
            diskFactory.FreeDisk(shootAtSth);
            shootAtSth = null;
        }

        if (scoreRecorder.getScore() > 1000 * round)       //每关500分才能进入下一关,重新倒数60秒
        {
            round++;
            leaveSeconds = count = 60;
        }

        if (round == 4)
        {
            StopAllCoroutines();
            state = State.WIN;
        }
        else if (leaveSeconds == 0 && scoreRecorder.getScore() < 500 * round)         //时间到,分数不够,输了
        {
            StopAllCoroutines();
            state = State.LOSE;
        }
        else
        {
            state = State.CONTINUE;
        }
    }
Beispiel #6
0
    public void Hit(Vector3 pos)
    {
        Ray ray = Camera.main.ScreenPointToRay(pos);

        RaycastHit[] hits;
        hits = Physics.RaycastAll(ray);
        bool not_hit = false;

        for (int i = 0; i < hits.Length; i++)
        {
            RaycastHit hit = hits[i];
            if (hit.collider.gameObject.GetComponent <DiskData>() != null)
            {
                for (int j = 0; j < dfree.Count; j++)
                {
                    if (hit.collider.gameObject.GetInstanceID() == dfree[j].gameObject.GetInstanceID())
                    {
                        not_hit = true;
                    }
                }
                if (!not_hit)
                {
                    return;
                }
                dfree.Remove(hit.collider.gameObject);
                sr.Record(hit.collider.gameObject);

                explosion.transform.position = hit.collider.gameObject.transform.position;
                explosion.GetComponent <ParticleSystem>().Play();
                hit.collider.gameObject.transform.position = new Vector3(0, -100, 0);
                df.FreeDisk(hit.collider.gameObject);
                break;
            }
        }
    }
    public void Hit(Vector3 pos)
    {
        Ray ray = Camera.main.ScreenPointToRay(pos);

        RaycastHit[] hits;
        hits = Physics.RaycastAll(ray);
        bool not_hit = false;

        for (int i = 0; i < hits.Length; i++)
        {
            RaycastHit hit = hits[i];
            if (hit.collider.gameObject.GetComponent <DiskData>() != null && game_over == false)
            {
                for (int j = 0; j < UFO_notshot.Count; j++)
                {
                    if (hit.collider.gameObject.GetInstanceID() == UFO_notshot[j].gameObject.GetInstanceID())
                    {
                        not_hit = true;
                    }
                }
                if (!not_hit)
                {
                    return;
                }
                UFO_notshot.Remove(hit.collider.gameObject);
                //记分员记录分数
                score_recorder.Record(hit.collider.gameObject);
                StartCoroutine(WaitingParticle(0.08f, hit, UFO_factory, hit.collider.gameObject));
                break;
            }
        }
    }
    public void Hit(Vector3 pos)
    {
        Ray ray = Camera.main.ScreenPointToRay(pos);

        RaycastHit[] hits;
        hits = Physics.RaycastAll(ray);
        bool notHit = false;

        foreach (RaycastHit hit in hits)
        {
            //射线打中物体
            if (hit.collider.gameObject.GetComponent <DiskData>() != null)
            {
                //射中的物体要在没有打中的飞碟列表中
                for (int j = 0; j < diskMissed.Count; j++)
                {
                    if (hit.collider.gameObject.GetInstanceID() == diskMissed[j].gameObject.GetInstanceID())
                    {
                        notHit = true;
                    }
                }
                if (!notHit)
                {
                    return;
                }
                diskMissed.Remove(hit.collider.gameObject);
                //记录分数
                scoreRecorder.Record(hit.collider.gameObject);
                diskFactory.FreeDisk(hit.collider.gameObject);
                break;
            }
        }
    }
Beispiel #9
0
 void Update()
 {
     if (playing)
     {
         if (Input.GetButtonDown("Fire1"))
         {
             Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             RaycastHit hit;
             //射线打中物体
             if (Physics.Raycast(ray, out hit) && hit.collider.gameObject.tag == "disk")
             {
                 disk_alive.Remove(hit.collider.gameObject);
                 hit.collider.gameObject.SetActive(false);
                 hit.collider.gameObject.transform.position = new Vector3(0, -9, 0);
                 //记分员记录分数
                 scoreRecorder.Record();
                 diskFactory.resetDisk(hit.collider.gameObject);
             }
         }
         //游戏结束
         if (round == 4)
         {
             gameOver();
             userGui._gameOver();
             playing = false;
         }
         //发送飞碟
         time += Time.deltaTime;
         if (time > 3)
         {
             time = 0;
             LoadResources();
         }
     }
 }
    public void Hit(Vector3 pos)
    {
        Ray ray = Camera.main.ScreenPointToRay(pos);

        RaycastHit[] hits;
        hits = Physics.RaycastAll(ray);
        bool not_hit = false;

        for (int i = 0; i < hits.Length; i++)
        {
            RaycastHit hit = hits[i];
            if (hit.collider.gameObject.GetComponent <DiskData>() != null)
            {
                for (int j = 0; j < diskNotHit.Count; j++)
                {
                    if (hit.collider.gameObject.GetInstanceID() == diskNotHit[j].gameObject.GetInstanceID())
                    {
                        not_hit = true;
                    }
                }
                if (!not_hit)
                {
                    return;
                }
                diskNotHit.Remove(hit.collider.gameObject);
                scoreRecorder.Record(hit.collider.gameObject);
                Transform explode = hit.collider.gameObject.transform.GetChild(0);
                explode.GetComponent <ParticleSystem>().Play();
                StartCoroutine(WaitingParticle(0.08f, hit, diskFactory, hit.collider.gameObject));
                break;
            }
        }
    }
Beispiel #11
0
    public void Check()
    {
        if (shootAtSth != null && shootAtSth.transform.tag == "UFO" && shootAtSth.activeInHierarchy)
        {
            scoreRecorder.Record(shootAtSth);
            ufoFactory.FreeUFO(shootAtSth);
            shootAtSth = null;
        }

        if (scoreRecorder.getScore() > 500 * round)
        {
            round++;
            leaveSeconds = count = 30;
        }

        if (round == 4)
        {
            StopAllCoroutines();
            state = State.WIN;
        }
        else if (leaveSeconds == 0 && scoreRecorder.getScore() < 500 * round)
        {
            StopAllCoroutines();
            state = State.LOSE;
        }
        else
        {
            state = State.CONTINUE;
        }
    }
Beispiel #12
0
 void OnTriggerEnter(Collider c)
 {
     if (c.gameObject.name == "Cylinder1" || c.gameObject.name == "Cylinder2" || c.gameObject.name == "Cylinder3" || c.gameObject.name == "Cylinder4" || c.gameObject.name == "Cylinder5")
     {
         gameObject.transform.parent.gameObject.GetComponent <Rigidbody>().isKinematic = true;
         gameObject.SetActive(false);
         float point = Mathf.Sqrt(this.gameObject.transform.position.x * this.gameObject.transform.position.x + this.gameObject.transform.position.y * this.gameObject.transform.position.y);
         recorder.Record(5 - (int)Mathf.Floor(point * 2));
     }
 }
Beispiel #13
0
    void OnTriggerEnter(Collider arrow_head)
    {
        Transform arrow = arrow_head.gameObject.transform.parent;

        if (arrow == null)
        {
            return;
        }
        arrow.GetComponent <Rigidbody>().isKinematic = true;
        arrow_head.gameObject.SetActive(false);
        recorder.Record(this.gameObject);
    }
Beispiel #14
0
    public void Hit(Vector3 position)
    {
        Ray ray = Camera.main.ScreenPointToRay(position);

        RaycastHit[] hits;
        hits = Physics.RaycastAll(ray);
        for (int i = 0; i < hits.Length; i++)
        {
            RaycastHit hit = hits[i];
            if (hit.collider.gameObject.GetComponent <DiskData>() != null)
            {
                scoreRecorder.Record(hit.collider.gameObject);
                hit.collider.gameObject.transform.position = new Vector3(0, -20f, 0);
            }
        }
    }
Beispiel #15
0
 void Update()
 {
     if (playing)
     {
         if (Input.GetButtonDown("Fire1"))
         {
             Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             RaycastHit hit;
             //射线打中物体
             if (Physics.Raycast(ray, out hit) && hit.collider.gameObject.tag == "disk")
             {
                 disk_alive.Remove(hit.collider.gameObject);
                 hit.collider.gameObject.SetActive(false);
                 hit.collider.gameObject.transform.position = new Vector3(0, -9, 0);
                 //记分员记录分数
                 scoreRecorder.Record();
                 diskFactory.resetDisk(hit.collider.gameObject);
             }
         }
         for (int i = 0; i < disk_alive.Count; i++)
         {
             GameObject temp = disk_alive[i];
             if (temp.transform.position.y < -6 && temp.gameObject.activeSelf == true)
             {
                 diskFactory.resetDisk(disk_alive[i]);
                 disk_alive.Remove(disk_alive[i]);
                 userGui.MissUFO();
             }
         }
         //游戏结束
         if (roundControl.getRound() == 4)
         {
             gameOver();
             userGui._gameOver();
             playing = false;
         }
         //发送飞碟
         time += Time.deltaTime;
         if (time > 3)
         {
             time = 0;
             LoadResources();
         }
     }
 }
    void OnTriggerEnter(Collider arrow_head)
    {
        Transform arrow = arrow_head.gameObject.transform.parent;

        if (arrow == null)
        {
            return;
        }
        if (arrow.tag == "arrow")
        {
            //speed 0
            arrow.GetComponent <Rigidbody>().velocity    = new Vector3(0, 0, 0);
            arrow.GetComponent <Rigidbody>().isKinematic = true;
            recorder.Record(this.gameObject);
            //arrow disapper
            arrow_head.gameObject.gameObject.SetActive(false);;
            arrow.tag = "hit";
        }
    }
Beispiel #17
0
 // if click the disk
 void FixedUpdate()
 {
     if (Input.GetButtonDown("Fire1"))
     {
         Vector3    mouse = Input.mousePosition;
         Camera     ca    = cam.GetComponent <Camera>();
         Ray        ray   = ca.ScreenPointToRay(mouse);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit))
         {
             if (hit.collider.gameObject.tag.Contains("Disk")) // if hit the disk
             {
                 DiskData theDisk = hit.collider.gameObject.GetComponent <DiskData>();
                 theDisk.reset();
                 FreeDisk(theDisk);
                 ScoreRecorder a = Singleton <ScoreRecorder> .Instance;
                 a.Record(theDisk); // get score
             }
         }
     }
 }
Beispiel #18
0
    public void Hit(Vector3 pos)
    {
        Ray ray = Camera.main.ScreenPointToRay(pos);

        RaycastHit[] hits;
        hits = Physics.RaycastAll(ray);
        bool not_hit = false;

        for (int i = 0; i < hits.Length; i++)
        {
            RaycastHit hit = hits[i];
            //射线打中物体
            if (hit.collider.gameObject.GetComponent <DiskData>() != null)
            {
                //射中的物体要在没有打中的飞碟列表中
                for (int j = 0; j < disk_notshot.Count; j++)
                {
                    if (hit.collider.gameObject.GetInstanceID() == disk_notshot[j].gameObject.GetInstanceID())
                    {
                        not_hit = true;
                    }
                }

                if (!not_hit)
                {
                    return;
                }

                disk_notshot.Remove(hit.collider.gameObject);
                //记分员记录分数
                score_recorder.Record(hit.collider.gameObject);
                //显示爆炸粒子效果
                Transform explode = hit.collider.gameObject.transform.GetChild(0);
                explode.GetComponent <ParticleSystem>().Play();
                //执行回收飞碟
                StartCoroutine(WaitingParticle(0.02f, hit, disk_factory, hit.collider.gameObject));
                break;
            }
        }
    }
Beispiel #19
0
    public void hit(Vector3 pos)
    {
        if (isGameOver == true)
        {
            return;
        }
        Ray ray = Camera.main.ScreenPointToRay(pos);

        RaycastHit[] hits;
        hits = Physics.RaycastAll(ray);
        bool not_hit = false;

        for (int i = 0; i < hits.Length; i++)
        {
            RaycastHit hit = hits[i];
            //射线打中物体
            if (hit.collider.gameObject.GetComponent <DiskData>() != null)
            {
                //射中的物体要在没有打中的飞碟列表中
                for (int j = 0; j < diskMissed.Count; j++)
                {
                    if (hit.collider.gameObject.GetInstanceID() == diskMissed[j].gameObject.GetInstanceID())
                    {
                        not_hit = true;
                    }
                }
                if (!not_hit)
                {
                    return;
                }
                Debug.Log("hit: " + hit.collider.gameObject.name);
                diskMissed.Remove(hit.collider.gameObject);
                scoreRecorder.Record(hit.collider.gameObject);
                hit.collider.gameObject.transform.position = new Vector3(0, -9, 0);
                break;
            }
        }
    }
Beispiel #20
0
    public void hit(Vector3 pos)
    {
        Ray ray = Camera.main.ScreenPointToRay(pos);

        RaycastHit[] hits;
        hits = Physics.RaycastAll(ray);
        for (int i = 0; i < hits.Length; i++)
        {
            RaycastHit hit = hits[i];

            if (hit.collider.gameObject.GetComponent <DiskData>() != null)
            {
                score_recorder.Record(hit.collider.gameObject);

                /**
                 * 如果飞碟被击中,那么就移到地面之下,由工厂负责回收
                 */

                hit.collider.gameObject.transform.position = new Vector3(0, -30, 0);
                hit.collider.gameObject.SetActive(false);
            }
        }
    }
Beispiel #21
0
 public void getScore(DiskData disk)
 {
     score_recorder.Record(disk);
 }
Beispiel #22
0
 // 失去目标,巡逻兵放弃追击
 public void OnGoalLost(GameObject patrol)
 {
     patrolActionManager.Patrol(patrol);
     scoreRecorder.Record();
 }
Beispiel #23
0
 public int getScore(DiskData disk)
 {
     recorder.Record(disk);
     return(disk.score);
 }
 public void Record(DiskData disk)
 {
     scoreRecorder.Record(disk);
 }