Skip to main content
Grammar
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

Best practice for givegiving properties to game objects

I'm not a noob in Unity although not the most experienced one, but during one of my project a noob question came to my mind! Strange but this never was an issue for me during my old projects... I became confused where should I initialize the basic properties of my agents.

Example: I have some workers (agents) in a strategy game and they can extract resources. For this I can create a script which executeexecutes the process,process; also I need a variable which define the maximum amount of collected resource the agent can carry. Normally I would create this property in the "Extracting" script which is fine, but should I really create different scripts for (almost) every propertiesproperty of an agent in different scripts?

There's some properties which are very general like "HP" for example... the HP can be used in many scripts and has no proper script to define/initialize it, but there's ton of other exampleexamples...

My idea to organize this thing to create a 'Property' script where I would write all of the properties which need for the given agent type. But in this case I have to connect the script to other ones which would use any property of this agent (by 'GetComponent<>'GetComponent<>)

Under the hood a GameObject is a class right? There's any way to add some variable (for properties) to the specified GameObject and access these variables from any scripts of which is attached to that GameObject?

What is the proper way to do this?

Best practice for give properties to game objects

I'm not a noob in Unity although not the most experienced one, but during one of my project a noob question came to my mind! Strange but this never was an issue for me during my old projects... I became confused where should I initialize the basic properties of my agents.

Example: I have some workers (agents) in a strategy game and they can extract resources. For this I can create a script which execute the process, also I need a variable which define the maximum amount of collected resource the agent can carry. Normally I would create this property in the "Extracting" script which is fine, but should I really create for (almost) every properties of an agent in different scripts?

There's some properties which are very general like "HP" for example... the HP can be used in many scripts and has no proper script to define/initialize it, but there's ton of other example...

My idea to organize this thing to create a 'Property' script where I would write all of the properties which need for the given agent type. But in this case I have to connect the script to other ones which would use any property of this agent (by 'GetComponent<>')

Under the hood a GameObject is a class right? There's any way to add some variable (for properties) to the specified GameObject and access these variables from any scripts of which is attached to that GameObject?

What is the proper way to do this?

Best practice for giving properties to game objects

I'm not a noob in Unity although not the most experienced one, but during one of my project a noob question came to my mind! Strange but this never was an issue for me during my old projects... I became confused where should I initialize the basic properties of my agents.

Example: I have some workers (agents) in a strategy game and they can extract resources. For this I can create a script which executes the process; also I need a variable which define the maximum amount of collected resource the agent can carry. Normally I would create this property in the "Extracting" script which is fine, but should I really create different scripts for (almost) every property of an agent?

There's some properties which are very general like "HP" for example... the HP can be used in many scripts and has no proper script to define/initialize it, but there's ton of other examples...

My idea to organize this thing to create a 'Property' script where I would write all of the properties which need for the given agent type. But in this case I have to connect the script to other ones which would use any property of this agent (by GetComponent<>)

Under the hood a GameObject is a class right? There's any way to add some variable (for properties) to the specified GameObject and access these variables from any scripts of which is attached to that GameObject?

What is the proper way to do this?

Source Link

Best practice for give properties to game objects

I'm not a noob in Unity although not the most experienced one, but during one of my project a noob question came to my mind! Strange but this never was an issue for me during my old projects... I became confused where should I initialize the basic properties of my agents.

Example: I have some workers (agents) in a strategy game and they can extract resources. For this I can create a script which execute the process, also I need a variable which define the maximum amount of collected resource the agent can carry. Normally I would create this property in the "Extracting" script which is fine, but should I really create for (almost) every properties of an agent in different scripts?

There's some properties which are very general like "HP" for example... the HP can be used in many scripts and has no proper script to define/initialize it, but there's ton of other example...

My idea to organize this thing to create a 'Property' script where I would write all of the properties which need for the given agent type. But in this case I have to connect the script to other ones which would use any property of this agent (by 'GetComponent<>')

Under the hood a GameObject is a class right? There's any way to add some variable (for properties) to the specified GameObject and access these variables from any scripts of which is attached to that GameObject?

What is the proper way to do this?