Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
11 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Photon Network Muzzleflash 0 Answers

How to get reference of the Local Game Player when a Game Scene is Loaded from a Lobby Scene [Multiplayer] 1 Answer

Cant Kill Multiplayer Player In Unity, Help! 0 Answers

Pushed back when applying NetworkTransform 1 Answer

Problem with RPC life 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges