Really sorry for my stupid question and my English. I am very new in unity networking.
As mentioned in the title, I tried to spawn a bullet but unable to.
My game now has a shooter Instantiated in the middle when the server starts.
The shooter can shoot at a total of 5 different points randomly which will rotate and shoot everywhere. The rotation of the shooter is synced but the bullet is unable to spawn.
Note
- I have registered Spawnable prefabs
for Shooter and bullet - Both shooter and bullets have
network identity and network
transform
The error message is
- did not find target for sync message
Below is my script
This is to spawn my shooter when the server starts
public class GMDodgeBullet : GMParent
{
public GameObject myShooter;
GameObject m_MyInstantiated;
public GameObject shooterPos;
public static bool canShoot;
public override void ServerStart()
{
base.ServerStart();
canShoot = true;
//Instantiate the Prefab
m_MyInstantiated = Instantiate(myShooter, shooterPos.transform.localPosition, shooterPos.transform.localRotation);
//Spawn the GameObject you assign in the Inspector
NetworkServer.Spawn(m_MyInstantiated);
}
}
The below script is attached to my shooter
[Header(“Bullet Settings”)]
public GameObject bulletPoints;
GameObject currentPoint;
public Rigidbody bullets;
public int bulletSpeed;
public float currentSpawnBulletRate;
GameObject serverBullet;
int index;
bool spawnInterval;
private void Start()
{
StartCoroutine(SpawnBullet());
spawnInterval = true;
currentSpawnBulletRate = 1;
}
IEnumerator SpawnBullet()
{
while (GMDodgeBullet.canShoot)
{
yield return new WaitForSeconds(1);
index = Random.Range(0, bulletPoints.Length);
currentPoint = bulletPoints[index];
Debug.LogError("HIHIHIHIHI " + index);
ShootBullet();
}
}
void ShootBullet()
{
Rigidbody bulletClone = Instantiate(bullets, currentPoint.transform.localPosition, currentPoint.transform.localRotation);
NetworkServer.Spawn(bulletClone.gameObject);
bulletClone.velocity = currentPoint.transform.TransformVector(new Vector3(0, 0, bulletSpeed));
Destroy(bulletClone.gameObject, 1f);
}
}
Please help me