Я пытаюсь синхронизировать пулю клиента с сервером, вот код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class PlayerShoot : NetworkBehaviour {
public PlayerShoot PlayerShootScript;
public Player PlayerScript;
public LayerMask WeaponEnemyLayers;
[Space]
public Transform[] WeaponfirePoints;
public GameObject[] WeaponBulletPrefab;
[Space]
public float WeaponScatter;
public float WeaponBulletForce;
[Space]
public int WeaponMinDamage;
public int WeaponMaxDamage;
public int WeaponChanceCritDamage;
public int WeaponCritDamage;
[Space]
public int WeaponOtskoks = 0;
public int WeaponProshivanies = 0;
void Update() {
if(isLocalPlayer)
if(PlayerScript.currentWeaponScript == null) { return; }
WeaponfirePoints = PlayerScript.currentWeaponScript.firePoints;
WeaponScatter = PlayerScript.currentWeaponScript.scatter;
WeaponBulletForce = PlayerScript.currentWeaponScript.bulletForce;
WeaponBulletPrefab = PlayerScript.currentWeaponScript.bulletPrefab;
WeaponMinDamage = PlayerScript.currentWeaponScript.minDamage;
WeaponMaxDamage = PlayerScript.currentWeaponScript.maxDamage;
WeaponChanceCritDamage = PlayerScript.currentWeaponScript.chanceCritDamage;
WeaponCritDamage = PlayerScript.currentWeaponScript.critDamage;
WeaponOtskoks = PlayerScript.currentWeaponScript.otskoks;
WeaponProshivanies = PlayerScript.currentWeaponScript.proshivanies;
WeaponEnemyLayers = PlayerScript.currentWeaponScript.enemyLayers;
if(Input.GetButtonDown("Fire1")) { PlayerScript.currentWeaponScript.mouseHide = true; }
if(Input.GetButtonUp("Fire1")) { PlayerScript.currentWeaponScript.mouseHide = false; }
if(PlayerScript.currentWeaponScript.weaponReloadnig) { return; }
if(!PlayerScript.currentWeaponScript.weaponReadyToShoot) { return; }
if(PlayerScript.currentWeaponScript.categoryWeapon == "Огнестрельное") {
if(PlayerScript.currentWeaponScript.mouseHide) {
Shoot();
}
}
}
[Client]
void Shoot() {
CmdSpawnBullet();
if(!PlayerScript.currentWeaponScript.infiniteMode) { PlayerScript.currentWeaponScript.currentAmmo -= 1; }
}
[Command]
void CmdSpawnBullet() {
for (int i = 0; i < WeaponfirePoints.Length; i++) {
Vector3 Angle = WeaponfirePoints[i].eulerAngles;
Angle.z += Random.Range(-WeaponScatter, WeaponScatter);
GameObject bullet = GameObject.Instantiate(WeaponBulletPrefab[Random.Range(0, WeaponBulletPrefab.Length)], WeaponfirePoints[i].position, Quaternion.Euler(Angle));
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
rb.velocity = bullet.transform.right * WeaponBulletForce;
int damage = Random.Range(WeaponMinDamage, WeaponMaxDamage+1);
bool CRIT = false;
NetworkServer.Spawn(bullet);
Bullet bulletScript = bullet.GetComponent<Bullet>();
bulletScript.EarlyShoot(PlayerShootScript);
bulletScript.DamageMastery(WeaponOtskoks, WeaponProshivanies, damage, WeaponCritDamage, WeaponChanceCritDamage, WeaponEnemyLayers);
}
}
[Command]
public void CmdHitOn(string _playerTag, string _playerID, int _damage, bool CRITICAL_DAMAGE) {
if(CRITICAL_DAMAGE) {
if(_playerTag == "Player") {
Player _player = GameManager.GetPlayer(_playerID);
_player.TakeCritDamage(_damage);
}
} else {
if(_playerTag == "Player") {
Player _player = GameManager.GetPlayer(_playerID);
_player.TakeDamage(_damage);
}
}
}
}
Когда сервер делает выстрелы, то клиент видит их, но сам клиент не может стрелять, я частично понимаю почему, но я не понимаю как сделать так, чтобы клиент мог стрелять и сервер видел его выстрелы.