drarem Posted April 27, 2015 Posted April 27, 2015 I would like to load a prefab and want to pass the player entity to the loaded prefab's attached script to initialize it its the start() function. How should I handle it? Thanks. Example: (player.lua) self.player.entity:SetPosition(0,0,0) local test = Prefab:Load("Prefabs/test/test.pfb") For test.pfb attached script: (test.lua) function Script:Start() self.startpos = ??? (somehow pass or get player entity position) self.endpos = self.entity:GetPosition() end Quote
beo6 Posted April 27, 2015 Posted April 27, 2015 i guess i would do it like this: Example: (player.lua) self.player.entity:SetPosition(0,0,0) local test = Prefab:Load("Prefabs/test/test.pfb", Prefab.NoStartCall) --prevent calling start on load if test.script~=nil then test.script.startpos = self.entity:GetPosition() --send position here test.script:Start() --call start here end For test.pfb attached script: (test.lua) function Script:Start() self.startpos = ??? (somehow pass or get player entity position) self.endpos = self.entity:GetPosition() end 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.