public void InitShop() { if (_list != null && _list.Count <= 0) { foreach (var o in _list) { GameObject.Destroy(o); } } _list = new List <GameObject>(); for (int i = 0; i < 3; ++i) { GameObject pills = GameObject.Instantiate <GameObject>(_bottle); pills.name = "sleeping pills(Clone)"; pills.tag = "Untagged"; pills.layer = 0; pills.transform.position = _pos[i]; pills.transform.rotation = Quaternion.Euler(0.0f, 180.0f, 0.0f); pills.GetComponent <Rigidbody>().isKinematic = true; PillBehaviour comp = pills.AddComponent <PillBehaviour>(); comp.ShopList = _list; _list.Add(pills); } GameObject.Destroy(_bottle); }
public override void OnLoad() { // Original AssetBundle b = LoadAssets.LoadBundle(this, "pills.unity3d"); GameObject original = b.LoadAsset <GameObject>("pill_bottle.prefab"); _bottle = GameObject.Instantiate <GameObject>(original); _bottle.name = "sleeping pills"; Material m = new Material(Shader.Find("Standard")); m.mainTexture = original.GetComponent <Renderer>().material.mainTexture; _bottle.GetComponent <Renderer>().material = m; GameObject.Destroy(original); b.Unload(false); // Load save PillSaveData data = PillSaveData.Deserialize <PillSaveData>(PillSaveData.SavePath); for (int i = 0; i < data.Pos.Count; ++i) { GameObject pills = GameObject.Instantiate <GameObject>(_bottle); pills.transform.position = data.Pos[i]; pills.transform.rotation = data.Rot[i]; PillBehaviour c = pills.AddComponent <PillBehaviour>(); c.ShopList = _list; c.Count = data.PillCount[i]; c.Activate(); c.SetBought(); } // Setup FatigueFsm = PlayMakerGlobals.Instance.Variables.FindFsmFloat("PlayerFatigue"); StressFsm = PlayMakerGlobals.Instance.Variables.FindFsmFloat("PlayerStress"); DrunkFsm = PlayMakerGlobals.Instance.Variables.FindFsmFloat("PlayerDrunk"); InitShop(); ConsoleCommand.Add(new PillCommand(this)); }