- Home /
Why isn't my RPC shooting code working?
using UnityEngine;
using System.Collections;
public class ShootingScripts : MonoBehaviour {
public Rigidbody bullet;
void Start () {
if (!networkView.isMine){
enabled = false;
}
}
void Update() {
if(Input.GetButtonDown("Fire1")){
networkView.RPC ("SpawnProjectile", RPCMode.All, transform.position, transform.rotation, 0);
}
}
[RPC]
void SpawnProjectile(Vector3 position, Quaternion rotation)
{
Rigidbody clone;
clone = Instantiate(bullet, position, rotation) as Rigidbody;
clone.AddForce(transform.right * 900);
}
}
Does anyone have any idea why my bullets aren't firing when I press the fire key? I have the script attached to an empty game object which is attached to the barrel of the gun. I'm not getting any error messages, it's just not shooting.
Comment
$$anonymous$$aybe the bullet is colliding with something like the player? Check this answer, it may help you: http://answers.unity3d.com/questions/316509/shooting-script-fires-projectiles-backwards.html
Your answer
Follow this Question
Related Questions
Problem with Network.Instantiate on instantiating a bullet. 1 Answer
Problems with a shooting script 1 Answer
Small RPC Code Not Working 1 Answer
Networking Error! 0 Answers
RPC Client and Server playing 1 Answer