# shoot method in network play...

**URL:** <https://discussions.unity.com/t/shoot-method-in-network-play/396669>\
**Category:** Multiplayer & Networking\
**Created:** [August 19, 2009, 4:03am UTC](https://discussions.unity.com/t/shoot-method-in-network-play/396669 "2009-08-19T04:03:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon\_17032817](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@anon\_17032817](https://discussions.unity.com/u/anon_17032817)\
**Post date:** [August 19, 2009, 4:03am UTC](https://discussions.unity.com/t/shoot-method-in-network-play/396669/1 "2009-08-19T04:03:24Z")

</div>

I apologize if there is already a thread on this (though I’ve scoured quite good I think).

I’ve been all through the network example and have learned quite a bit (at least I feel like I have :). However, much to my dismay, I’ve been unsuccessful in getting shooting to work.

Currently I have players able to join just fine, they walk around great, however shooting seems to be quite the trick. Every time the mouse is pushed on any of the machines, everyone fires 🙂 kinda fun, but not obviously intentional.

I’m assuming I should be using RPC’s (as I get an error when using Network.Instantiate() saying that Rigidbody isn’t ideal for this, which seems required to make the shots move…)

The way I understand it, is the RPC’s need to have a Network View attached to the objects as well.

The script is attached to an object that is invisible that has a Network View(observing this script). The Shot also has a network view attached to it (observing the shot’s transform).

```auto
var projectile : Rigidbody;
var initialSpeed = 90.0;
var reloadTime = 0.5;
private var lastShot = -10.0;

function Update(){
	if (Input.GetButton ("Fire1")){
	   
	   if (Time.time > reloadTime + lastShot) {
			lastShot = Time.time;
			networkView.RPC("Fire", RPCMode.AllBuffered);
		  }
  } 
}

@RPC
function Fire () {
		// create the shot
		var newProjectile : Rigidbody;
		newProjectile = Instantiate (projectile, transform.position, transform.rotation);
		
		// give it force
		newProjectile.velocity = transform.TransformDirection(Vector3 (0, 0, initialSpeed));
		
		// Ignore collisions between the missile and the character controller
		Physics.IgnoreCollision(newProjectile.collider, transform.root.collider);
		Physics.IgnoreCollision(newProjectile.collider, transform.parent.collider);
}

```

I know for sure there is something I’m not grasping but any explanations or help would be awesome (even if it’s broad) 🙂 Great forums and thanks in advance 🙂

---

<div class="post-metadata">

**Author:** ![perlohmann](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/perlohmann/32/497335_2.png) [@perlohmann](https://discussions.unity.com/u/perlohmann)\
**Post date:** [August 19, 2009, 7:11am UTC](https://discussions.unity.com/t/shoot-method-in-network-play/396669/2 "2009-08-19T07:11:49Z")

</div>

this is because it is the same script running on all instances of your shooting “player”. since they are all enabled they all capture you mouse down.

What you could do is either set enable=false on your non local players (that way update will not be called) or test on NetworkView.isMine (dont know how your architecture is they might all be owned by a server in such a case the isMine approach wont work)together with the Input…

//perlohmann

---

<div class="post-metadata">

**Author:** ![anon\_17032817](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@anon\_17032817](https://discussions.unity.com/u/anon_17032817)\
**Post date:** [August 19, 2009, 3:35pm UTC](https://discussions.unity.com/t/shoot-method-in-network-play/396669/3 "2009-08-19T15:35:31Z")

</div>

thanks perlohmann, I’m gonna give these suggestions a go and post my results (if they are good enough to share!:)) Thanks again!
