Ejemplo n.º 1
0
    public void shoot()
    {
        GameObject bullet = mF.getBullet(tankType.Player);

        bullet.transform.position = new Vector3(player.transform.position.x, 1.5f, player.transform.position.z) +
                                    player.transform.forward * 1.5f;
        bullet.transform.forward = player.transform.forward;
        Rigidbody rb = bullet.GetComponent <Rigidbody>();

        rb.AddForce(bullet.transform.forward * 20, ForceMode.Impulse);
    }
Ejemplo n.º 2
0
    public void shoot()
    {
        GameObject bullet = mF.getBullet(tankType.Player);        //获取子弹,传入的参数表示发出子弹的坦克类型

        bullet.transform.position = new Vector3(player.transform.position.x, 1.5f, player.transform.position.z) +
                                    player.transform.forward * 1.5f; //设置子弹位置
        bullet.transform.forward = player.transform.forward;         //设置子弹方向
        Rigidbody rb = bullet.GetComponent <Rigidbody>();

        rb.AddForce(bullet.transform.forward * 20, ForceMode.Impulse);        //发射子弹
    }
Ejemplo n.º 3
0
 IEnumerator shoot()
 {//协程实现npc坦克每隔1s进行射击
     while (!gameover)
     {
         for (float i = 1; i > 0; i -= Time.deltaTime)
         {
             yield return(0);
         }
         if (Vector3.Distance(transform.position, target) < 20)
         {                                                                  //和玩家坦克距离小于20,则射击
             myFactory  mF     = Singleton <myFactory> .Instance;
             GameObject bullet = mF.getBullet(tankType.Enemy);              //获取子弹,传入的参数表示发射子弹的坦克类型
             bullet.transform.position = new Vector3(transform.position.x, 1.5f, transform.position.z) +
                                         transform.forward * 1.5f;          //设置子弹
             bullet.transform.forward = transform.forward;                  //设置子弹方向
             Rigidbody rb = bullet.GetComponent <Rigidbody>();
             rb.AddForce(bullet.transform.forward * 20, ForceMode.Impulse); //发射子弹
         }
     }
 }
Ejemplo n.º 4
0
 IEnumerator shoot()
 {
     while (!gameover)
     {
         for (float i = 1; i > 0; i -= Time.deltaTime)
         {
             yield return(0);
         }
         if (Vector3.Distance(transform.position, target) < 20)
         {
             myFactory  mF     = Singleton <myFactory> .Instance;
             GameObject bullet = mF.getBullet(tankType.Enemy);
             bullet.transform.position = new Vector3(transform.position.x, 1.5f, transform.position.z) +
                                         transform.forward * 1.5f;
             bullet.transform.forward = transform.forward;
             Rigidbody rb = bullet.GetComponent <Rigidbody>();
             rb.AddForce(bullet.transform.forward * 20, ForceMode.Impulse);
         }
     }
 }