Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
Maybe you will synchronize the leaves on the bushes? To synchronize a bullet, it is enough to send to all clients: departure time, departure coordinates, direction. And then they draw it themselves
. In general, no one usually visualizes bullets with models. Strongly expensive.
Implemented like this:
[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;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question