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

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); 
        } 
      } 
    } 
主站蜘蛛池模板: 衢州市| 承德市| 启东市| 龙海市| 肃宁县| 梁平县| 舒城县| 翼城县| 云龙县| 宁阳县| 丰台区| 营山县| 阿图什市| 治多县| 湖北省| 丰原市| 民权县| 乌鲁木齐市| 巴塘县| 赫章县| 东至县| 永年县| 弋阳县| 无棣县| 佛山市| 醴陵市| 宜昌市| 保康县| 苍南县| 蒙阴县| 神农架林区| 潮安县| 长泰县| 双辽市| 辽宁省| 临邑县| 城口县| 郎溪县| 洞头县| 伊宁市| 柳州市|