|
I have read every manual, user guide, and post I can find, but I still don't understand this. I have a "Dispatcher" and a "Runner". The Dispatcher uses Instantiate() to create a Runner prefab. That prefab needs to tell the Dispatcher when it has collided with something so that the Dispatcher can take action. How does the Runner (Instance) communicate back with the Dispatcher (Parent Script)? Dispatcher.js (attached to Empty game object as central controller): Runner.js (attached to Prefab): What is wrong with my thinking? How else can you code an intelligent program without a central controller? I need someone to be the referee. I have seen a great demo on this, (Intergalactic Sheep Pong) but it wasn't using Instantiated Prefabs. I also don't see how the Dispatcher can communicate with Runners either since it re-uses newRunner for every instantiation. It can only commuicate during this one LateUpdate() unless it saves a tag or something. Thanks!
(comments are locked)
|
|
You are right - you need to teach the runner about the dispatcher. Runner.jsDispatcher.jsNote if you used owner in Awake on the Runner then you could actually modify the value in the prefab before calling instantiate. Another option for a central controller is the Singleton pattern - in that case you do this: Dispatcher.jsRunner.js
Jul 31 '12 at 10:49 PM
whydoidoit
In "teaching the runner about the dispatcher", I tried exactly what you suggested at first, but Unity would not let me drag a script onto a Prefab for the Dispatcher slot in the Inspector. The only options for that slot are primitives (cube,sphere,plane,etc.) It "feels" like a Unity bug. I am using 3.5.3f3. Is that a known issue?
Jul 31 '12 at 11:06 PM
dlynch13
You need to allocate that at run time - like the example I show here. You can't set it up that way in a prefab (the setting of scripts on assets won't work because the prefab cannot refer back to a scene object).
Jul 31 '12 at 11:07 PM
whydoidoit
Excellent information: "the prefab cannot refer back to a scene object." Good to know!! So then how does Runner.js (in the first example) know what "var owner : Dispatcher;" refers to? That is a slot in the Runner prefab that Runner.js is attached. What if I had multiple objects with a Dispatcher script attached? How does owner.collisionCount know who is the owner?
Jul 31 '12 at 11:27 PM
dlynch13
Its the line in dispatcher that tells it which is its owner:
Jul 31 '12 at 11:28 PM
whydoidoit
(comments are locked)
|
