Scripts unintentionally sharing data (using public classes)
For some context, I have a simple "EnemyController" script in which there is a public class named "EnemyData". In that class there are a few variables. Now let's say I Instantiate 2 prefabs, that are identical, only the names are different ("Enemy 1" and "Enemy 2"). Both of them have the "EnemyController" attached. Here is the problem: when I do "Enemy.GetComponent().EnemyData = new EnemyData" (This is an example) one "Enemy" becomes the "Main" (Just a word to describe). Let's say the "Main" Enemy is "Enemy 1", then "Enemy 2" has all of the "EnemyData" duplicated from "Enemy 1", even when the values from "Enemy 1" change. The strange thing is that if I don't copy the whole class like "Script.Class = new Class" (Simplified) and instead replace all the values individually like "Script.Class.Value1 = new Class.Value1; Script.Class.Value2 = new Class.Value2" (Again Simplified) the values between "Enemies" don't get shared. I hope I was not too difficult to understand, if anyone needs clarification please message me, and if anyone has an idea why this is not working, please help :)
Your answer
Follow this Question
Related Questions
Destroy GameObject in my own Class 0 Answers
Referencing uninstantiated GameObject within a class? 0 Answers
class1 calling class2, no value? 1 Answer
Regular class in a script is NullReference, but I promise it is not 1 Answer
Using a subclass in the inspector in place of a parent class and accessing the subclass variables 1 Answer