- Home /
Question by
dvidunis · Aug 26, 2011 at 05:54 PM ·
scenecontrollerfunctionportal
Using A function in another game object
heres my code: portalEnter.js(Character)
function OnControllerColliderHit (hit : ControllerColliderHit) {
if (Input.GetKeyUp(KeyCode.UpArrow)) {
hit.gameObject.Enter();
}
}
Portal.js(portal)
var mapid:int;
var X:float;
var Y:float;
function Enter (a:int) {
Application.LoadLevel(mapid);
}
i want "portalEnter" to call Enter() in "Portal" and in the new scene set the X and the Y in "Portal" To The Position of the player in the new scene. how do i do that? i have tried EVERYTHING please help.
Comment
Answer by FTheCloud · Aug 26, 2011 at 06:20 PM
You use BroadcastMessage.
Here's how the first part of your code should look instead.
var a : int;
function OnControllerColliderHit (hit : ControllerColliderHit) {
if (Input.GetKeyUp(KeyCode.UpArrow)) {
hit.gameObject.BroadcastMessage("Enter",a,SendMessageOptions.DontRequireReceiver);
}
}
Answer by DaveA · Aug 26, 2011 at 06:20 PM
Have you tried this? http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Components.html