Search Unity

Question MLAPI Networked Weapon Firing

Discussion in 'Multiplayer' started by cam_r_n, Oct 11, 2021.

  1. cam_r_n

    cam_r_n

    Joined:
    Oct 9, 2021
    Posts:
    1
    I'm currently trying to get the basics down for multiplayer and am currently working on getting weapon firing to work between games. I'm specifically following this set of videos [https://www.youtube.com/watch?v=i-q5AhstcqA&list=PLbxeTux6kwSAseRmJeCyvkANHsI16PoM6&index=4] after already setting up basic player movement, shooting, etc, but my method of shooting doesn't line up with the video and don't know how to apply the video to my weapon firing

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using MLAPI;
    4. using MLAPI.NetworkVariable;
    5.  
    6. public class GunShoot : NetworkBehaviour
    7. {
    8.     public ParticleSystem fireFX;
    9.     public float fireRate = 1f;
    10.     private float timeToFire = 1 / 3f;
    11.  
    12.     void Start()
    13.     {
    14.        
    15.     }
    16.  
    17.     void Update()
    18.     {
    19.         PlayerShoot();
    20.     }
    21.     void PlayerShoot()
    22.     {
    23.         if (IsLocalPlayer)
    24.         {
    25.             if (Input.GetButtonDown("Fire") && Time.time >= timeToFire)
    26.             {
    27.                 Debug.Log("Pew");
    28.                 timeToFire = Time.time + (1f / fireRate);
    29.             }
    30.         fireFX.Play();
    31.         }
    32.     }
    33. }