Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Kylelem62 · Feb 21, 2013 at 07:34 AM · networkinventory

Syncronize Items over network

How would I go about instantiating an item on the network that everyone can pick up and add to their inventory? I have a system that works flawlessly in singleplayer but once someone connects it stops working. Also how would one manage to synchronize a object added as a child of a bone so that all can see? Here are my attempts:

This is the inventory script on the player prefab (pardon my messy code):

 using UnityEngine;
 using System.Collections;
 
 public class Inventory : MonoBehaviour {
     bool invOpen=false;
     int x=1,y=1;
     ArrayList itemsInInventory=new ArrayList(100);
     // Use this for initialization
     void Start () {
     
     }
     bool ticked;
     // Update is called once per frame
     void Update () {
         if (Input.GetButton("Inventory"))
             
         {
             if (!ticked)
             {    
                 ticked=true;
                 if (invOpen)
                 {
                     (GetComponent("Esc")as Esc).PauseGame(false);
                     invOpen=false;
                 }
                 else
                 {
                     (GetComponent("Esc")as Esc).PauseGame(true);
                     invOpen=true;
                 }
             }
         }
         else
             ticked=false;
         GameObject[] loot = GameObject.FindGameObjectsWithTag("Loot");
         int i;
         for(i=0;i<loot.Length;i++)
         {
             if(Vector3.Distance(loot[i].transform.position,transform.position)<15&&Input.GetKey(KeyCode.Q))
             {
                 if (networkView.isMine)
                 Add ((loot[i].GetComponent("Item")as Item).pickup());
             }
         }
     }
     void Add(GameObject item)
     {
         if(item!=null)
         itemsInInventory.Add(item);
     }
     void CloseGui()
     {
         
     }
     void OnGUI()
     {
         if (invOpen)
         {
             GUI.Window(1,new Rect(x,y,500,700),InvWindow,"Inventory");
         }
     }
 
     void InvWindow (int id)
     {
         int i,j=0,k=0;
         for(i=1;i-1<itemsInInventory.Count;i++)
         {
             if(GUI.Button(new Rect((x)*(j*100),(y)*(k*100)+15,100,100),(((GameObject)itemsInInventory.ToArray()[i-1]).GetComponent("Item")as Item).ID))
             {
                 if (networkView.isMine)
                 (((GameObject)itemsInInventory.ToArray()[i-1]).GetComponent(typeof(Item))as Item).Equip((GetComponentInChildren(typeof(RightHandMount))as RightHandMount).getTransform(RightHandMount.Mount.RightHand));
                 //((Item)Instantiate((Item)itemsInInventory.ToArray()[i-1])).drop(transform.position);
                 //itemsInInventory.Remove(itemsInInventory.ToArray()[i-1]);
             }
             j++;
             if(j==5)
             {
                 j=0;
                 k++;
             }
             
         }
         
         GUI.DragWindow ();
     }
 }

Then this is my Item script:

 using UnityEngine;
 using System.Collections;
 
 public class Item : MonoBehaviour {
     public enum EquipSlots{
         LeftHand,
         RightHand,
         Head
     }
     public string ID = "";
     public bool IsEquipable = false;
     public EquipSlots Slot = EquipSlots.RightHand;
     
     
     
     
      bool isdrop = true;
     
     
     // Use this for initialization
     void Start () {
         
     }
     public GameObject pickup()
     {
         if(isdrop)
         {
             isdrop=false;
             gameObject.SetActive(false);
             return gameObject;
         }
         else return null;
     }
     public void drop(Vector3 position)
     {
         isdrop=true;
         transform.position=position;
         gameObject.SetActive(true);
     }
     public GameObject Equip(Transform parent)
     {
         transform.parent=parent;
         transform.localPosition=Vector3.zero;
         gameObject.SetActive(true);
         print ("sldkf");
         return this.gameObject;
     }
     
     void OnMouseEnter()
     {
         GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
         int i;
         for(i=0;i<players.Length;i++)
         {
             if(Vector3.Distance(players[i].transform.position,transform.position)<7)
             {
                 highlight(true);
             }
             else
                 highlight(false);
         }
     }
     void OnMouseExit()
     {
         highlight(false);
     }
     void OnMouseDown()
     {
         
     }
     void highlight(bool highlight)
     {
         
     }
     // Update is called once per frame
     void Update () {
         
         
     }
 }


The highlight will be implemented later, and the mounts will not be individual scripts. Any help would be much appreciated.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Fattie · Feb 21, 2013 at 09:42 AM

http://answers.unity3d.com/questions/326626/games-with-multiple-maps.html

note the "important note" and "critical note" and pls vote up useful answers! :)

Comment
Add comment · Share
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

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Best way to sync scene with new connections? 0 Answers

Can't send RPC function since no connection was started 1 Answer

gameObject.find "Player" belonging to this network player??? 1 Answer

OnConnectedToServer called multiple times 1 Answer

Get "actual bytes sent" in script 1 Answer


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