Sending values to other gameobjects

Ok, first off, i am still a bit of nub when it comes to code, so bare with me :slight_smile:

I am able to send values to scripts in the same gameobject, but for some reason i cannot find a way to send values to a script on another gameobject.

I have a gameobject called book. When the player picks up the book, the book is deleted and a skill point would be added to the skill points manager as part of the character stats. The book and the code for picking up the book is on one gameobject, and the skills stuff is on the Main Camera.

My last experiment was using sendmessage, and here is the code for it. If there is something else i should be using, throw it at me :slight_smile:

Skills_pane

var spoint : int = 0;

function skillpoint(spoint : int){

spoint += 1;

}

skillbook

 var dist : int;
var player : Transform;
var book : Transform;

function Start () {

}

function Update () {

dist = Vector3.Distance(player.transform.position,book.transform.position);

if (dist == 1) {
	if (Input.GetKeyUp("e")) {
gameObject.SendMessage ("skillpoint");
DestroyObject (gameObject);

}
}
}

Anything anyone can suggest will be a lifesaver.

First off, Send message will only send that message to anything on your current game object. Broadcast message will send it to the parent and all of its children. However since you are dealing with 2 seperate game objects I would call on the skillpoint function directly from your other game object. (I also changed your dist line because you already declared those variables as Transforms. There is no need to write player.transform.position… just say player.position. Just an FYI :slight_smile: Here is a modification of your script. Try messing with this… it may not be exactly what you want… but this is my idea of where to go. :

var cam : Camera; // drop your camera that has the skills script into this variable
var dist : int;
var player : Transform;
var book : Transform;

function Update () {

dist = Vector3.Distance(player.position, book.position);

if (dist == 1) {
    if (Input.GetKeyUp("e")) {
cam.GetComponent(Skills_pane).skillpoint();
Destroy(gameObject);

}
}
}