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

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); 
        } 
      } 
    } 
主站蜘蛛池模板: 平江县| 德化县| 开封市| 邳州市| 来安县| 桐庐县| 新昌县| 通州市| 通化市| 大同市| 赤城县| 前郭尔| 翼城县| 措美县| 鹤壁市| 原阳县| 邵武市| 江阴市| 南部县| 黑龙江省| 方正县| 威信县| 信丰县| 梁河县| 旅游| 化州市| 海伦市| 海宁市| 平和县| 信宜市| 潼关县| 津南区| 定陶县| 济宁市| 永寿县| 宜兰县| 吐鲁番市| 承德市| 大宁县| 深水埗区| 漾濞|