I am learning Unity using JavaScript. I’m not a noob to scripting in general, but am at the beginning of this particular learning curve. I did several searches, but found nothing relevant (although I did get an error page saying the the search engine was taking a break at some point).
Here is the background…
I have an empty object that casts a ray. This empty object stores where the ray hits as global Vector3 variable.
I am intending to use another script attached to the main camera to use that global Vector3 to place a retical graphic in 2d space via WorldToScreenPoint.
The issue is that it doesn’t see the global variable. Here is the relevant code for the raycaster…
//targetRetical.js
static var tigerRetical : Vector3 = Vector3.zero;
function Update () {
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection (Vector3 (0,0,-1)),hit, 150)) {
var tigerRetical : Vector3 = hit.point;
}
}
And here is the script that is attempting to read the global…
var target : Vector3 = (targetRetical.tigerRetical);
function Update() {
print ("vector is " + target);
}
Basic troubleshooting that I have done so far is…
- Printing the value of
“targetRetical” in the first script.
This works as expected. - Printing the value of “target” in
the second script. This does not
work as expected. It prints the
vector as “0.0, 0.0, 0.0”. - I have added a particle emitter to
visually confirm that the raycast
moves with the object casting the
ray in script #1. This works as expected. - I have also confirmed that I was
creating globals and reading them from other scripts correctly by creating a
global Int in script #1 and printing
it successfully in script #2.
I just don’t get what I’m missing…
Since Hellium converted his comment into an answer, let me accept it on your behalf. Though, I'm curious how that actually happened? The playmode tint color certainly doesn't change itself. So at some point in time you had to change it manually to pitch black. -The tint color has immediate effect. Didn't you test run right after the change? I always pick a rather random "redish" color every time I setup Unity but I immediately test run to see if the contrast is good enough to work with and that the color is not too distractive.
– Bunny83