/// <summary> /// Sets the mounted weapon to the specified instance. Only works when called from the server. /// If the weapon is null, the current weapon is removed instantly. /// </summary> /// <param name="spot">The spot. Should be on this vehicle, and not null!</param> /// <param name="weapon">The weapon instance, not prefab!</param> public void SetWeapon(MountedWeaponSpot spot, MountedWeapon weapon) { if (!JNet.IsServer) { Debug.LogError("Cannot set mounted weapon when not on server."); return; } if (spot == null) { Debug.LogError("Spot is null."); return; } if (spot.Vehicle != this) { Debug.LogError($"This spot is not on the current vehicle ({this.gameObject.name}), cannot set mounted weapon."); return; } if (spot.Size != weapon.Size) { Debug.LogError($"Size is not correct. Expected {spot.Size}, got {weapon.Size}... Weapon will not be placed."); return; } spot.SetMountedWeapon(weapon); }
/// <summary> /// Sets the mounted weapon to the mounted weapon with the specified prefab name. Only works when called from the server. /// If the weapon is null, the current weapon is removed instantly. /// </summary> /// <param name="spot">The spot. Should be on this vehicle, and not null!</param> /// <param name="mountedWeaponName">The name of the prefab.</param> public void SetWeapon(MountedWeaponSpot spot, string mountedWeaponName) { if (string.IsNullOrWhiteSpace(mountedWeaponName)) { Debug.LogError("Null or whitespace name. Cannot set mounted weapon!"); return; } var spawnable = Spawnables.Get <MountedWeapon>(mountedWeaponName); if (spawnable != null) { var spawned = Instantiate(spawnable); SetWeapon(spot, spawned); JNet.Spawn(spawned.gameObject); } else { Debug.LogError($"Failed to spawn mounted weapon from name {mountedWeaponName}."); } }