Hi,
I have a scene with a path with a series of objects (spheres) spaced along it. When the First Person Controller approaches a given sphere, I would like it to trigger its own popup window of text. Here’s what I have so far in my PlayerCollisions.js:
private var currentPageMarker : GameObject;
private var pageMarkerName : String;
function OnTriggerEnter(collisionInfo : Collider){
if(collisionInfo.gameObject.tag == "pageMarker" ){
pageMarkerName = collisionInfo.gameObject.name;
pageMarkerOn(pageMarkerName);
}
}
function OnTriggerExit(collisionInfo : Collider){
if(collisionInfo.gameObject.tag == "pageMarker" ){
pageMarkerName = collisionInfo.gameObject.name;
pageMarkerOff(pageMarkerName);
}
}
function pageMarkerOn(pageMarkerName:String){
print("Hello from " + pageMarkerName);
}
function pageMarkerOff(pageMarkerName:String){
print("Goodbye from " + pageMarkerName);
}
When the FPC hits a sphere object (tagged “pageMarker”) it makes a trigger event happen which calls the function pageMarkerOn() which takes the name of the particular object as its parameter “pageMarkerName”.
So far all I’ve been able to do with the pageMarkerName is print it to the console, confirming which marker was hit by the FPC. I would like to be able to use the pageMarkerName information somehow to call its corresponding text window from another script, Narrative.js. Here’s what I have so far for Narrative.js:
var menuSkin : GUISkin;
var areaWidth : float = 200;
var areaHeight : float = 400;
private var CurrentTextAsset : TextAsset;
private var whichText : String;
function Start () {
whichText = "Text_01";
CurrentTextAsset = Resources.Load(whichText, TextAsset);
}
function OnGUI () {
var ScreenX = Screen.width - areaWidth;
var ScreenY = 0;
var windowRect : Rect = (Rect(ScreenX, ScreenY, areaWidth, areaHeight));
newWindow = GUI.Window (0, windowRect, DoMyWindow, "Narrative");
}
function DoMyWindow(){
GUI.Box(Rect (10, 20, (areaWidth - 20), (areaHeight - 30)), CurrentTextAsset.text);
}
The function Start() assigns the name of the TextAsset to the variable whichText. Another variable, CurrentTextAsset, then loads the corresponding TextAsset from the Resource folder. The functions OnGUI() and DoMyWindow() then display the corresponding text in a GUI.Window which uses a GUI.Box to display the text.
My problem is that I can’t figure out how write a function in Narrative.js that can be called from PlayerCollisions.js with PlayerCollisions.js providing the parameter that tells Narrative.js which TextAsset to call. In pseudocode, it would go something like this:
PlayerCollisions.js:
function pageMarkerOn(pageMarkerName:String){
Narrative.setWhichText(foo); // "foo" is somehow derived from pageMarkerName
}
Narrative.js:
function setWhichText(foo:String){
foo = whichText; // then the new value for whichText would be available througout the script
}
My problem is that I don’t know enough about communication between scripts to do this. I have tried labeling variables and functions static and tried and some getter/setter things, but I can’t see to get anything but null values and/or lots of error messages. Can anybody help me with this, or point me to a tutorial on how to get one script to call a function in another script with parameters involved? Thanks.
Zaffer