Search Unity

How to copy values of one script to the same script on a different gameobject

Discussion in 'Scripting' started by DarkEcho, Sep 30, 2014.

  1. DarkEcho

    DarkEcho

    Joined:
    Jul 7, 2014
    Posts:
    233
    I have 2 scripts both called 'Item' they are both the same just with different Variable values.

    Script A is in a List and Script B is on a gameobject. I want to copy the values of Script A to Script B without going through each variable (Im guessing it should be doable as they are the same script).

    Any alternatives are welcome.

    Im basically making of copy of an item from the players inventory to be dropped and the orignal copy to be deleted
     
    Last edited: Sep 30, 2014
  2. Glockenbeat

    Glockenbeat

    Joined:
    Apr 24, 2012
    Posts:
    669
    You'll need to use reflection for that, but that is generally pretty heavy. Also it has compatibility issues with iOS.
    I'd go for a method which manually maps source to destination.