- Home /
The question is answered, right answer was accepted
Problem with Network.Instantiate on instantiating a bullet.
I'm trying to make a fps game (multiplayer of course) and I'm trying to make a gun. I tried with the normal Instantiate(bulletPrefab, blahblahblah) but it didn't show up on the other clients. So I tried Network.Instantiate and it said this
Assets/shoot.js(11,43): BCE0017: The best overload for the method 'UnityEngine.Network.Instantiate(UnityEngine.Object, UnityEngine.Vector3, UnityEngine.Quaternion, int)' is not compatible with the argument list '(UnityEngine.Transform, UnityEngine.Vector3, UnityEngine.Quaternion)'.
Here's the script var bulletPrefab : Transform; var bulletSpeed : float = 600;
function Update ()
{
if(Input.GetButtonDown("Fire1"))
{
if (!bulletPrefab || !bulletSpeed)
{
} else {
var bulletCreate = Network.Instantiate(bulletPrefab,GameObject.Find("SpawnPoint").transform.position,Quaternion.identity);
bulletCreate.rigidbody.AddForce(transform.forward * bulletSpeed);
}
}
}
Answer by Hugs Are Drugs · Oct 14, 2012 at 08:10 PM
The error says you need an integer at the end of it.
You're doing
`var bulletCreate = Network.Instantiate(bulletPrefab,GameObject.Find("SpawnPoint").transform.position,Quaternion.identity);`
but what you need to do is
`var bulletCreate = Network.Instantiate(bulletPrefab,GameObject.Find("SpawnPoint").transform.position,Quaternion.identity, ANY INTEGER);`
Try that and if that doesn't work I don't really know, I personally work with C# and not UnityScript, but what people new to Unity always seem to do is make a first person shooter and when they try to do that they make it instantiate a physical bullet, I don't recommend doing that, NOBODY recommends doing that unless it's a slow moving projectile for example, an RPG.
What you should use for a bullet is a Physics.Raycast, I recommend you read some of this:
http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html.