I’m just about on the verge of giving up on all this after weeks of trying to solve one problem… so… last shot at this…
I have 2 objects - Small Frame and Large Frame. Renderer on Large Frame is disabled. Clicking on Small Frame should make Large Frame visible. Large Frame is the direct child of Small Frame. I’ve tried this two different ways…
Option A:
Code for Small Frame:
#pragma strict
// this works fine
function Start () {
renderer.enabled = false;
}
//as does this
function OnMouseEnter () {
renderer.enabled = true;
}
//this is the problem
function OnMouseDown () {
BroadcastMessage ("ShowPlanets");
}
//though this is fine too
function OnMouseExit () {
renderer.enabled = false;
}
Here is the code for Large Frame
renderer.enabled = false;
function Start () {
}
function OnShowPlanets () {
renderer.enabled = true;
}
And when clicking on Small Frame I still get a message telling me ShowPlanets has no receiver.
Option B:
Here is the other code I’ve tried using for Small Frame:
#pragma strict
var largeFrame : GameObject;
// this works fine
function Start () {
renderer.enabled = false;
}
//as does this
function OnMouseEnter () {
renderer.enabled = true;
}
//this is the problem
function OnMouseDown () {
BroadcastMessage ("ShowPlanets", largeFrame, SendMessageOptions.DontRequireReceiver);
}
//though this is fine too
function OnMouseExit () {
renderer.enabled = false;
}
Doing that - after double checking I have the proper game object selected in the inspector - results in no error message… and in fact, absolutely nothing happening when I click on Small Frame.
Like I said, I’m about done with this so I hope this can finally get solved.
You’re using “ShowPlanets” in BroadcastMessage but you have no function called that.
–Eric
That was a transcription error on my part due to typing rather than copy/pasting. it actually say
function ShowPlanets () {
With the function name fixed, the only way the situation you described in Option A wouldn’t work is if the Large Frame object was inactive (rather than just having the renderer disabled).
–Eric
I checked that too and as far as I can tell it’s active.
The alternative (which I actually preferred) was to use GUI rather than an object for Large Frame, but the other objects involved (planets) were then obscured. So I’m left trying to fix this.
Your ShowPlanets function doesn’t take any arguments, but you try to send it a GameObject called “largeFrame” in BroadcastMessage.
var largeFrame : GameObject;
function OnMouseDown () {
BroadcastMessage ("ShowPlanets", largeFrame, SendMessageOptions.DontRequireReceiver);
}
Therefore, ShowPlanets must accept a GameObject in its parameter list.
function ShowPlanets(frame : GameObject) {
}
That’s something new to try at least. Let me see what happens.
I just tried this and it works:
from an empty scene I added 1 cube called smallframe position 0,0,0 scale 1,1,1
attach this script to it smallframe.js
#pragma strict
function OnMouseDown () {
BroadcastMessage ("ShowPlanets");
}
added another cube to the scene and made it a child of the first cube, called it largeframe set position to 2,0,0 and scale to 2,2,2 and attached this script to it largeframe.js
renderer.enabled = false;
function ShowPlanets () {
renderer.enabled = true;
}
press play, click the small cube and the large on appears.
Heres the package
1476153–81438–$smallframe-largeframe.unitypackage (4.07 KB)