Hi..this is one of my first forays into javascript (nearly all of my experience is in c++), and I've hit a snag that I cant quite find on my own...this is a (very) simple script meant to log the player's position every 5 seconds and to relocate the player to the logged position if they enter water. It is executing correctly except that the position is not being logged; only the initial position is being used.
Also, when the code is compiled inside unity, the variable waterLevel does not show up as being alterable without actually opening the script and changing the code directly. Is there a trick to making it do so?
I apologize for asking such a basic question on here, but I'm not sure what exactly the problem is...It compiles fine, but the behavior I think I wrote just isnt happening.
UPDATE: Although I could not get the 5-second interval to work correctly, I did manage to get it to log the position every time the script is run as long as the controller is 15 units above the set sea level.
Thanks for the answers; I appreciate them.
Have a nice day.
private var pos : Vector3; var waterLevel :int = 90;function Start () {
pos=transform.position; counter=0;
}
function Update () {
` if (transform.position.y<waterLevel)
{
transform.position=pos;
counter=0;} if (transform.position.y>waterLevel+15) { pos=transform.position; }
`
}
edited to correct sloppy code
edited to reflect new code accomplishing task(though not the intended way)