[SyncVar] Vector3 syncBulletStartPosition;
[SyncVar] Quaternion syncBulletStartRotation;
[SyncVar] bool syncTrueFire;
/// <summary>
/// Метод для осуществления стрельбы
/// </summary>
private void Update()
{
if(isLocalPlayer)
{
if (Input.GetButton("Fire1"))
{
//CmdShoot();
int weapon = 0;
// Create the Bullet from the Bullet Prefab
GameObject bullet = (GameObject)Instantiate(
bulletPref[weapon],
bulletPivot[weapon].position,
bulletPivot[weapon].rotation);
CmdSendBullet(bulletPivot[weapon].position, bulletPivot[weapon].rotation);
}
}
}
[Command]
void CmdSendBullet(Vector3 startPosition, Quaternion startRotation)
{
syncBulletStartPosition = startPosition;
syncBulletStartRotation = startRotation;
syncTrueFire = true;
}
/// <summary>
/// Вызов всех еобходимых методов для смены и синхронизации оружия
/// </summary>
void FixedUpdate()
{
SpawnBulletToAllClients();
}
void SpawnBulletToAllClients()
{
if (!isLocalPlayer)
{
if (syncTrueFire == true)
{
int weapon = 0;
GameObject bullet = (GameObject)Instantiate(
bulletPref[weapon],
bulletPivot[weapon].position,
bulletPivot[weapon].rotation);
CmdSyncTrueFire();
syncTrueFire = false;
}
}
}
[Command]
void CmdSyncTrueFire()
{
syncTrueFire = false;
}