Changing a String to the Value of Another with Broadcasts

I’m trying to create a system where if you click on an object, it’s name shows up on the GUI. This is my selection script (Object):

var objectName : String;
var reciever : GameObject;

function OnMouseDown () {
	reciever.BroadcastMessage ("Selected", objectName);
}

So when you click on the object it broadcasts to the Main Camera.
This is the GUI script:

var selected : String;
var guiHeight = 250;

    function OnGUI() {
         GUI.Box(Rect(Screen.width / 4,695,Screen.width / 2,guiHeight),selected);
    }
    
   function Selected (damage : String) {
        selected==damage;
    }

Now my problem is that, though there are no errors, it doesn’t work. The GUI string doesn’t change.

1 Answer

1

hmm maybe it’s because you used == instead of =

== is for comparison while = is for assigning

try

selected = damage;

Also try to keep your variables and function names different :smiley:

Thanks, it worked.

u're welcome :D

o and dont forget to accept the answer! :D