Ok im ginna make this as quick as i can…Multiplayer game with two dufferent types of player prefab. They both have the same gun script. And its this…
sing UnityEngine.Networking;
using System.Collections;
using System;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class shoot : NetworkBehaviour {
public Rigidbody Bullet;
public float speed = 20f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if (!isLocalPlayer)
{
return;
}
if (Input.GetButtonDown ("Fire1"))
{
Rigidbody CreateObjectThing = Instantiate (Bullet,
transform.position, transform.rotation)as Rigidbody;
CreateObjectThing.velocity =
transform.TransformDirection (new Vector3 (0, 0, speed));
}
}
}
This script above ^^^^^^^^ spawns a bullet and then i put a script vvvvvv on the bullet prefab…the script is below.
using UnityEngine;
using System.Collections;
public class bulletStuff : MonoBehaviour {
public Rigidbody RigidBod;
public GUIText textwinned;
// Use this for initialization
void Start ()
{ }
// Update is called once per frame
void Update ()
{
}
public void OnCollisionEnter(Collision coll)
{
if (coll.gameObject.tag == "BulletBreakers")
{
Destroy (RigidBod.gameObject);
}
if (coll.gameObject.tag == "PlayerSnoop")
{
GameObject.Find ("WinScreen").SetActive (true);
GameObject.Find ("WinImage").SetActive (true);
textwinned.text = ("YAY U WIN, DERP");
Destroy (RigidBod.gameObject);
}
if (coll.gameObject.tag == "PlayerDerp")
{
GameObject.Find ("WinScreen").SetActive (true);
GameObject.Find ("WinImage").SetActive (true);
textwinned.text = ("YAY U WIN, SNOOP");
Destroy (RigidBod.gameObject);
}
}
}
Derp is player 2 and snoop is player one. But the part that is failing is… The update function on the shoot script. The part where it says…
if (!isLocalPlayer)
{
return;
}
It works fine for my player movement script and my player turn script but not for my shoot script…WHYYYYY???