Photon Instantiate a prefab and add script on it.

I would to drop some item and the other player can pick it up too…
I already instantiate it using PhotonNetwork.Instantiate () and I want to add some script for picking up function.
The gameobject has already appearing in hierarchy but no with my script…

Here’s my instantiating code :

GameObject dropItem = PhotonNetwork.Instantiate ("ItemOnTheGround", gameObject.transform.position, Quaternion.identity, 0);
                dropItem.AddComponent<PickUpItem> ();
                dropItem.GetComponent<PickUpItem> ().item = this.gameObject.GetComponent<ItemOnObject> ().item;

so How I can add component to my instantiated object ?

Good day @ilham_fzn28 !

I dont know exactly what is PhotonNetwork, but looking your script, it seems good. You fisrt instantiate a GO calling it dropItem, and then you are adding components to thet dropItem.

Where is the problem? it should be working… Are you sure the name of the component is thatone?

What version of unity are you using? AddComponent is beeing obsolete as UnityManuals says, but i dont know whats the new way to do it.

Try to use this for add the component, to be sure unity understand what are you adding, but im not sure if is corretc or if it works:

 dropItem.AddComponent<PickUpItem>() as PickUpItem;

Bye :smiley: