Attaching an integer variable to gameobject

Hi,

Is it possible to attach an integer or any other type of variable to a gameobject and then access it other scripts? I have a number of blocks in my game and want to attach some extra data to it and access this data for various operations. Its similar to adding metadata to an object. Hope u get what i want to say.

Thanks.

if you just add a script to the object with a global var you have what you want.

Ok. Thanks. Will it not affect the performance if i attach scripts to 40-50 objects or say more than that? Just asking.

GameObjects don’t do anything without scripts or components on them. If you want GameObjects with scripts already attached, take a look at the reference for Prefabs and Instantiate. I don’t know of a limit.

Only performance issue is to keep the Update() code in each as minimal as you can.

Thanks for the tip. Will remember that. I have checked the prefab section but wanted to know if there is another way or not. :slight_smile:

Scripts that don’t do anything (except store variables) have no effect on performance.

–Eric