- Home /
Question by
King_JMK · Jul 12, 2015 at 06:31 PM ·
unity 5multiplayerfpsnetwork
Detacting Collision Over Photon Network
I Made A MultiPlayer FPS the movement works and its smooth but the bullet detaction doesnt work for some reason ...
here is the scripts i use
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Health : MonoBehaviour {
public Transform Player;
public PhotonView Charac;
public float H;
public float Hheal;
public Text HText;
public bool CanDie;
public Movement MoveScript;
public GameObject Gun1;
public GameObject Gun2;
public float GunNumber;
public bool CanChange;
void Start () {
Gun1.SetActive (true);
Gun2.SetActive (false);
GunNumber = 1;
}
void Intilize (){
Player = GetComponent<Transform> ();
MoveScript = Player.GetComponent<Movement>();
}
void Update () {
// Hit Detatciton
Hgain = MoveScript.Hhit;
if(Hgain == 1 ){
H = H + 10;
}
Hlost = MoveScript.Hloss;
Hlost = Hlost * 2;
H = H - Hlost;
// Respawn
if (H <= 0 && CanDie == true){
SpawnMyPlayer();
}
HText.text = "H " + Mathf.Round (H / 10) * 10;
}
// Hit Detaction 2
void OnCollisionEnter(Collision collision) {
if (collision.gameObject.tag == "Bullet" ) {
H = H - (30 / Random.Range(1,3));
Debug.Log ("HIT!");
}
}
//Respawning
void SpawnMyPlayer(){
PhotonNetwork.Destroy(Charac);
H = 100;
GameObject MyPlayer =(GameObject) PhotonNetwork.Instantiate ("Character" , Vector3.zero,Quaternion.identity , 0);
MyPlayer.GetComponent<CharacterController> ().enabled = true;
MyPlayer.GetComponent<CapsuleCollider> ().enabled = false;
((MonoBehaviour)MyPlayer.GetComponent("Movement")).enabled = true ;
((MonoBehaviour)MyPlayer.GetComponent("CharCamera")).enabled = true ;
((MonoBehaviour)MyPlayer.GetComponent("Health")).enabled = true ;
MyPlayer.transform.FindChild ("Cam").gameObject.SetActive (true);
MyPlayer.transform.FindChild ("Canvas").gameObject.SetActive (true);
}
}
the second
using UnityEngine;
using System.Collections;
public class Network : MonoBehaviour {
void Start (){
Connect ();
}
void Connect (){
PhotonNetwork.ConnectUsingSettings ("1.0.0");
}
void OnGUI(){
GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString() );
}
void OnJoinedLobby(){
Debug.Log ("OnJoinedLobby");
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed(){
Debug.Log ("OnJoinedLobbyFailed");
PhotonNetwork.CreateRoom (null);
}
void OnJoinedRoom(){
Debug.Log ("JoinedRoom");
SpawnMyPlayer ();
}
void SpawnMyPlayer(){
GameObject MyPlayer =(GameObject) PhotonNetwork.Instantiate ("Character" , Vector3.zero,Quaternion.identity , 0);
MyPlayer.GetComponent<CharacterController> ().enabled = true;
MyPlayer.GetComponent<CapsuleCollider> ().enabled = false;
((MonoBehaviour)MyPlayer.GetComponent("Movement")).enabled = true ;
((MonoBehaviour)MyPlayer.GetComponent("CharCamera")).enabled = true ;
((MonoBehaviour)MyPlayer.GetComponent("Health")).enabled = true ;
MyPlayer.transform.FindChild ("Cam").gameObject.SetActive (true);
MyPlayer.transform.FindChild ("Canvas").gameObject.SetActive (true);
}
the third
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Shooting: MonoBehaviour {
public Text AText;
public Transform Player;
public Transform Cam;
public Movement MoveScript;
public AudioSource Reload;
public AudioSource Fire;
public float A;
public float Ammo;
public float Aclips;
public float GunDam;
public bool CanFire;
private float Re;
private float Ampk;
void Start (){
}
void Intilize (){
MoveScript = Player.GetComponent<Movement>();
}
void Update () {
Ampk = MoveScript.Amhit;
if(!Reload.isPlaying){
if (A == 0 && Aclips > 0) {
Re = Ammo - A ;
Aclips = Aclips - Re;
A = Ammo;
Reload.Play ();
}
if (Input.GetKeyDown (KeyCode.R) && Aclips > 0 && A < Ammo) {
Re = Ammo - A ;
Aclips = Aclips - Re;
A = Ammo;
Reload.Play ();
}
if(Ampk == 1 ){
Aclips = Aclips + Ammo;
Ampk = 0;
Reload.Play();
}
}
if (CanFire == true && A > 0) {
if (Input.GetButtonDown ("Fire1")) {
if (!Fire.isPlaying) {
Fire.Play ();
Shoot ();
}
}
}
AText.text = "A " + A + " / " + Aclips;
}
void Shoot(){
GameObject fire;
A = A - 1;
fire = PhotonNetwork.Instantiate ("Ammo" ,transform.position , Player.rotation , 0 );
fire.GetComponentInChildren<Rigidbody>().position = transform.position + (GetComponentInChildren<Rigidbody>().transform.localPosition = new Vector3 (0.0f, 0.6f, 0.0f));
fire.GetComponentInChildren<Rigidbody>().velocity = transform.TransformDirection (Vector3.forward * 100);
Player.Rotate (Vector3.left * Time.deltaTime * 100);
}
}
can anyone tell me what is the problem ..
and yes i did put the photon view thing
}
Comment