Search Unity

Third Party Need help about how to integration this script with photon unity network.

Discussion in 'Multiplayer' started by warwolf2015, Mar 2, 2017.

  1. warwolf2015

    warwolf2015

    Joined:
    Jun 7, 2014
    Posts:
    26
    I'm try to make a play can carrying object in multiplayergmae using unity photon networking
    please help.

    here is my code.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class PickupObject : MonoBehaviour {
    6.     GameObject mainCamera;
    7.     bool carrying;
    8.     GameObject carriedObject;
    9.     public float distance;
    10.     public float smooth;
    11.     // Use this for initialization
    12.     void Start () {
    13.         mainCamera = GameObject.FindWithTag("MainCamera");
    14.     }
    15.    
    16.     // Update is called once per frame
    17.     void Update () {
    18.         if(carrying) {
    19.             carry(carriedObject);
    20.             checkDrop();
    21.             //rotateObject();
    22.         } else {
    23.             pickup();
    24.         }
    25.     }
    26.  
    27.     void rotateObject() {
    28.         carriedObject.transform.Rotate(5,10,15);
    29.     }
    30.  
    31.     void carry(GameObject o) {
    32.         o.transform.position = Vector3.Lerp (o.transform.position, mainCamera.transform.position + mainCamera.transform.forward * distance, Time.deltaTime * smooth);
    33.         o.transform.rotation = Quaternion.identity;
    34.     }
    35.  
    36.     void pickup() {
    37.         if(Input.GetKeyDown (KeyCode.E)) {
    38.             int x = Screen.width / 2;
    39.             int y = Screen.height / 2;
    40.  
    41.             Ray ray = mainCamera.GetComponent<Camera>().ScreenPointToRay(new Vector3(x,y));
    42.             RaycastHit hit;
    43.             if(Physics.Raycast(ray, out hit)) {
    44.                 Pickupable p = hit.collider.GetComponent<Pickupable>();
    45.                 if(p != null) {
    46.                     carrying = true;
    47.                     carriedObject = p.gameObject;
    48.                     //p.gameObject.rigidbody.isKinematic = true;
    49.                     p.gameObject.GetComponent<Rigidbody>().useGravity = false;
    50.                 }
    51.             }
    52.         }
    53.     }
    54.  
    55.     void checkDrop() {
    56.         if(Input.GetKeyDown (KeyCode.E)) {
    57.             dropObject();
    58.         }
    59.     }
    60.  
    61.     void dropObject() {
    62.         carrying = false;
    63.         //carriedObject.gameObject.rigidbody.isKinematic = false;
    64.         carriedObject.gameObject.GetComponent<Rigidbody>().useGravity = true;
    65.         carriedObject = null;
    66.     }
    67. }
    68.  
     
  2. Karsten

    Karsten

    Joined:
    Apr 8, 2012
    Posts:
    187