官术网_书友最值得收藏!

Shooting bullet

Whenever the player clicks the left mouse button, we check whether the total elapsed time since the last fire has passed the fire rate of the weapon. If it has, then we create a new Bullet object at the SpawnPoint variable's position. In this way, we can prevent the player from shooting a continuous stream of bullets:

    void UpdateWeapon() 
    { 
      if (Input.GetMouseButtonDown(0)) 
      { 
        elapsedTime += Time.deltaTime; 
        if (elapsedTime >= shootRate) 
        { 
          //Reset the time 
          elapsedTime = 0.0f; 
 
          //Instantiate the bullet 
          Instantiate(Bullet, bulletSpawnPoint.position,  
          bulletSpawnPoint.rotation); 
        } 
      } 
    } 
主站蜘蛛池模板: 理塘县| 疏附县| 沙坪坝区| 贡觉县| 义马市| 碌曲县| 连城县| 兴海县| 黄浦区| 于都县| 托里县| 德昌县| 万荣县| 台前县| 大同县| 柘荣县| 莒南县| 弥勒县| 图木舒克市| 枝江市| 大足县| 夏邑县| 濮阳县| 江阴市| 濮阳县| 南木林县| 中西区| 大冶市| 乐昌市| 左权县| 申扎县| 项城市| 手机| 吴川市| 泉州市| 广宗县| 嵩明县| 临泉县| 景泰县| 上饶县| 临湘市|