SmartlyDressedGames / Unturned-3.x-Community

Community portion of the Unturned-3.x repo. If you have access to the source code you can find it here:
https://github.com/SmartlyDressedGames/Unturned-3.x/
86 stars 18 forks source link

Add component #1008

Closed Ziiyqol-coder closed 5 years ago

Ziiyqol-coder commented 5 years ago

How i can add a MonoBehaviour component to item whats in inventory/on ground?

RoyIL commented 5 years ago

Open cmd, type "shutdown /r" and it'll add some crazy components into the gameobject 💦

Alekaei commented 5 years ago

less unturned related and more unity related, look up how to add components to gameobjects

surv0013 commented 5 years ago

You can't add component to item in inventory, but you can add component to item on ground.

public class Compoent : MonoBehaviour
{

}
ItemDrop item;

item.interactableItem.gameObject.AddComponent<Component>();
ghost commented 5 years ago

You can't add component to item in inventory, but you can add component to item on ground.

public class Compoent : MonoBehaviour
{

}
ItemDrop item;

item.interactableItem.gameObject.AddComponent<Component>();

Is it possible? As far as I know, you can use only the classes existing in the game, but if you write your own, the game will not read the script.

RoyIL commented 5 years ago

Lol where did you hear that? 🤦‍♂️

Sl4vP0weR commented 5 years ago

You can't add component to item in inventory, but you can add component to item on ground.

public class Compoent : MonoBehaviour
{

}
ItemDrop item;

item.interactableItem.gameObject.AddComponent<Component>();

Hmmmm, did you tried this ?

surv0013 commented 5 years ago

I apologize for misleading you. I examined the game code and found that the gameObject is not created on the server, only information about it is stored.

ghost commented 5 years ago

I don’t understand, are you talking about modding and adding a script to GameObject or writing a plugin on the server?

SDGNelson commented 5 years ago

For performance reasons the server doesn't spawn any game objects for items, instead tracking a few details with the ItemData class. If you only need to associate some info while the item is on the ground you could use a dictionary using the instance ID as a key, but once the items are in players inventories there's unfortunately no per-instance storage. One workaround may be to use harmony to patch in an extra field, but that's outside my know-how.

(Also answered #1040)