- Home /
How to pass a int from a object to another
Hi, I have a problem, I have an object part of another bigger and I want this small object pass one of his ints to the bigger one, I have done this on the big object:
number= playerTriggered.gameObject.SendMessage("SayNumberOfPlayer");
And this one on the smaller:
function SayNumberOfPlayer() : int {
return numberofplayer;
}
But I experience this error:
Assets/nuevo/Scripts/Tank.js(16,78): BCE0022: Cannot convert 'void' to 'int'.
What I'm doing wrong?
Answer by Meltdown · May 14, 2011 at 12:00 PM
The problem you are having is SendMessage doesn't return a value, so you are assigning your int to 'no' value.
Rather use GameObject.GetComponent
It allows you to get a get a reference to your object. Once you have a reference to the object, you can then create a variable and assign it to the value of your SayNumberOfPlayer() method returned via GetComponent.
Your answer
Follow this Question
Related Questions
Object to int 1 Answer
Pass a function(float) as variable 2 Answers
Script not function if mouse is on object 1 Answer
how do I make a Object getcomponent and call a function 1 Answer
pragma strict issues with iOS 1 Answer