- Home /
javascript to respawn player in 2d platformer not working
Hey, this is my first time n unity answers so please tell me if i'm doing something wrong. I'm creating a 2d platform game and I have a JavaScript respawn script. It checks if the player is at y -80, and if that's true it restarts the scene. Anyway, I get this error: `Assets/respawn.js(8,24): BCE0020: An instance of type 'UnityEngine.GameObject' is required to access non static member 'transform'.
this is my script: (I added it to my player)
#pragma strict
function Start () {
}
function Update () {
if (GameObject.transform.position.y <= -80)
{
Application.LoadLevel("main");
}
}
(sorry the code option markup didn't work so I did it like this)
Answer by Graham-Dunnett · May 07, 2014 at 12:46 PM
if (transform.position.y <= -80)
Yeah. "GameObject" isn't a specific object, it's the name of a type of object. That's why it doesn't have a transform. To access the transform of the object your script is attached to, you just use "transform" as Graham Dunnett wrote here.
thanks, I would love to give you a likeylikey but I can't yet :)
Your answer
Follow this Question
Related Questions
Making the players head face toward the location of the mouse? 1 Answer
WebGL build is getting cached in the browser, users cannot see updates... 0 Answers
BCE0019: 'Add' is not a member of 'UnityEngine.Transform[]' 1 Answer
Error: not a member of 'UnityEngine.GameObject[]'. 2 Answers
Java Script Error since Unity 5? 1 Answer