Search Unity

copy data in javascript class instead of make pointer

Discussion in 'Scripting' started by TJB, Dec 24, 2009.

  1. TJB

    TJB

    Joined:
    Mar 20, 2007
    Posts:
    146
    Code (csharp):
    1. class MyInfo {
    2.     var one = "";
    3.     var two = "";
    4. }
    5.  
    6. function () {
    7.     var hi = new MyInfo();
    8.     hi.one = "hello";
    9.     hi.two = "world";
    10.  
    11.     var hiTwo = hi;
    12. }
    The above code make hiTwo a pointer to the same object as hi... how would i copy the values from hi to a new MyInfo that hiTwo points to?

    Thanks for any help you can provide.
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    you would clone the object.
     
  3. TJB

    TJB

    Joined:
    Mar 20, 2007
    Posts:
    146
    What's the code to do this?

    I looked through the unity script reference and msdn and the only thing i found was icloneable which doesn't make sense to me....