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

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); 
        } 
      } 
    } 
主站蜘蛛池模板: 宁波市| 汉中市| 澄江县| 叶城县| 米林县| 雷州市| 建德市| 广南县| 固安县| 奉节县| 兖州市| 哈巴河县| 贵定县| 柳河县| 咸宁市| 鸡泽县| 盐边县| 察隅县| 昭苏县| 治多县| 南投市| 浑源县| 虎林市| 齐齐哈尔市| 峨眉山市| 乐安县| 岳阳县| 佛冈县| 灵台县| 门源| 阿尔山市| 崇仁县| 五河县| 宁安市| 华宁县| 万安县| 无锡市| 木兰县| 磴口县| 广河县| 黄陵县|