There are lots of instantiated prefabs. Info from it is transmitted while it crosses a trigger zone. Some of these are calculated custom variables.
I can print the custom variables from the instantiated prefabs.
I can get the trigger zone to report standard things like "...transform.position" or "...transform.localEulerAngles", but not stuff I make up. Intellisense seems to see everything I am trying to get, and everything compiles.
What's the best manner to perform this? Here's what I've tried:
Prefabs' Script:
public float infoToSend;
void Update(){
float infoToSend = 10f //...actually, there's some math here, but it's a float.
}
print("Sender: " + infoToSend); //Works.
Receiver Script on Trigger Zone:
void OnTriggerStay2D(Collider2D other){
print("Receiver: " + other.transform.position); //Works Fine.
print("Receiver: " + other.transform.localRotation); //Works Fine.
float infoReceived = other.GetComponent<PrefabsScript>().infoToSend;
print("Receiver: " + infoReceived); //Does not work!
}
Any help, either fixing this arrangement or directing me to a different method, would be appreciated. Thanks.
Edit to display the solution:
Corrected Prefabs' Script (changed third line down):
public float infoToSend;
void Update(){
this.infoToSend = 10f //...actually, there's some math here, but it's a float.
}
print("Sender: " + infoToSend); //Works.
Correct Receiver Script on Trigger Zone:
void OnTriggerStay2D(Collider2D other){
print("Receiver: " + other.transform.position); //Works Fine.
print("Receiver: " + other.transform.localRotation); //Works Fine.
float infoReceived = other.GetComponent<PrefabsScript>().infoToSend;
print("Receiver: " + infoReceived); //Does not work!
}
Many thanks, again! There's so many places to begin with, it's tough to find a "Beginner course" to cover everything.