[HideInInspector] public DynValue CreateProjectileAbs(Script s, string sprite, float xpos, float ypos, string layerName = "") { LuaProjectile projectile = (LuaProjectile)BulletPool.instance.Retrieve(); if (sprite == null) { throw new CYFException("You can't create a projectile with a nil sprite!"); } SpriteUtil.SwapSpriteFromFile(projectile, sprite); projectile.name = sprite; projectile.owner = s; projectile.gameObject.SetActive(true); projectile.ctrl.MoveToAbs(xpos, ypos); //projectile.ctrl.z = Projectile.Z_INDEX_NEXT; //doesn't work yet, thanks unity UI projectile.transform.SetAsLastSibling(); //projectile.ctrl.UpdatePosition(); projectile.ctrl.sprite.Set(sprite); if (layerName != "") { try { projectile.transform.SetParent(GameObject.Find(layerName + "Bullet").transform); } catch { try { projectile.transform.SetParent(GameObject.Find(layerName + "Layer").transform); } catch { } } } DynValue projectileController = UserData.Create(projectile.ctrl); //Texture2D tex = (Texture2D)projectile.GetComponent<Image>().mainTexture; //projectile.selfAbs = UnitaleUtil.GetFurthestCoordinates(tex.GetPixels32(), tex.height, projectile.self); return(projectileController); }
private DynValue CreateProjectileAbs(Script s, string sprite, float xpos, float ypos) { LuaProjectile projectile = (LuaProjectile)BulletPool.instance.Retrieve(); SpriteUtil.SwapSpriteFromFile(projectile, sprite); projectile.owner = s; projectile.gameObject.SetActive(true); projectile.ctrl.MoveToAbs(xpos, ypos); //projectile.ctrl.z = Projectile.Z_INDEX_NEXT; //doesn't work yet, thanks unity UI projectile.transform.SetAsLastSibling(); projectile.ctrl.UpdatePosition(); DynValue projectileController = UserData.Create(projectile.ctrl); return(projectileController); }
private static Projectile bPrefab; // bullet prefab //private static int currentProjectile = 0; /// <summary> /// Initialize the pool with POOLSIZE Projectiles ready to go /// </summary> private void Start() { instance = this; LuaProjectile luapr = Resources.Load <LuaProjectile>("Prefabs/LUAProjectile 1"); if (luapr != null && luapr.ToString().ToLower() != "null") { bPrefab = luapr; } pool.Clear(); for (int i = 0; i < POOLSIZE; i++) { createPooledBullet(); } }
// Sets the parent of a bullet. Can't be used on an enemy or projectile public void SetParent(LuaProjectile parent) { transform.SetParent(parent.transform); }