Search Unity

Lua and Unity

Discussion in 'Scripting' started by George Foot, Feb 22, 2012.

  1. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Hey, I've been having a look at this today and am trying something but I keep getting the error:

    This only happens with my custom stuff, the actual UnityEngine.GameObject works fine, changing the name doesn't help either.

    Something like this works fine:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using LuaInterface;
    4.  
    5. public class KLITest : MonoBehaviour {
    6.  
    7.     Lua L;
    8.  
    9.     void Start()
    10.     {
    11.         L = new Lua();
    12.  
    13.         string[] script =
    14.             {
    15.                 "luanet.load_assembly(\"UnityEngine\")",
    16.                 "GameObject = luanet.import_type(\"UnityEngine.GameObject\")",
    17.                 "gameObject = new GameObject(\"HI\")"
    18.             };
    19.         foreach (var line in script)
    20.         {
    21.             L.DoString(line);
    22.         }
    23.     }
    24. }
    25.  
    But as soon as I try using a custom type it doesn't work, this is the code I'm trying:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using LuaInterface;
    4.  
    5. public class KLITest : MonoBehaviour {
    6.  
    7.     Lua L;
    8.  
    9.     void Start()
    10.     {
    11.         L = new Lua();
    12.  
    13.         string[] script =
    14.             {
    15.                 "luanet.load_assembly(\"Exposed\")",
    16.                 "GameObject = luanet.import_type(\"Exposed.GameObject\")",
    17.                 "gameObject = new GameObject(\"HI\")"
    18.             };
    19.         foreach (var line in script)
    20.         {
    21.             L.DoString(line);
    22.         }
    23.     }
    24. }
    25.  
    And this is the class I'm trying to use:

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. namespace Exposed
    6. {
    7.     public class GameObject
    8.     {
    9.  
    10.         internal UnityEngine.GameObject gameObject;
    11.         //Variables
    12.         public bool activeSelf;
    13.         public bool activeInHierarchy;
    14.  
    15.         //Functions
    16.         public void SetActive(bool value)
    17.         {
    18.             gameObject.SetActive(value);
    19.         }
    20.         //Constructors
    21.         public GameObject(string name)
    22.         {
    23.             gameObject = new UnityEngine.GameObject(name);
    24.         }
    25.         //Update to update the GameObject
    26.         void Update()
    27.         {
    28.             activeSelf = gameObject.activeSelf;
    29.             activeInHierarchy = gameObject.activeInHierarchy;
    30.         }
    31.     }
    32. }
    33.  
    I'm sure the code works as this test code in C# works as expected(Creates a new GameObject called "HI")

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using Exposed;
    5.  
    6. public class Test : MonoBehaviour
    7. {
    8.     void Start ()
    9.     {
    10.         Exposed.GameObject hi = new Exposed.GameObject("HI");
    11.     }
    12. }
    13.  
     
  2. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Theme reincarnation...
    As for me - perfect for config files, thanks for share, it works with Unity5 fine.
     
  3. denebhyde

    denebhyde

    Joined:
    Dec 15, 2013
    Posts:
    83