Hi
i’m new to coding and i just tried to code a respawn script for my game and i get two errors they are
Assets/Scripts/Respawn.js(3,4):UCE0001: ‘;’ expected. Insert a semicolon at the end.
Assets/Scripts/Respawn.js(4,5):UCE0001: ‘;’ expected. Insert a semicolon at the end.
Heres my script:
#pragma strict
var character : boolean;
int sealevel = 170;
char spawnpoint;
function Update ()
{
if(character.position.y < sealevel);
(character.transform.position.spawnpoint);
}
2 Answers
2
system
November 9, 2013, 2:44pm
2
Try this…:
var spawnPoint : Vector3;
var character : GameObject;
var sealevel = 170;
function Update () {
if(character.position.y < sealevel){
character.position = spawnPoint;
Debug.Log("Player has respawned");
}
}
function OnDrawGizmos () {
// Draw a semitransparent blue cube at the transforms position
Gizmos.color = Color (1,0,0,.5);
Gizmos.DrawCube (Vector3(0,sealevel,0), Vector3 (character.position.x + 100,1,character.position.z + 100));
}
There are a number of errors in this code…not just syntax error but conceptual errors. You may want to take some time to work through some tutorials.
Line 1 - a character needs to be a GameObject or a Transform
Line 3 - you are mixing C# and Javascript here. This is not the way to declare an ‘int’ in Javascript, plus you really want this value to be a float.
Line 5 a spawnpoint needs to be a position in 3D space…A Vector3, and again this is not how you declare variables in Javascript.
Line 10 - you have a ‘;’ at the end of your ‘if’, which terminates the ‘if’ statement.
Line 12 - you don’t have an assignment here.
You may have wanted your code to be:
#pragma strict
var character : Transform;
var sealevel = 170.0;
var spawnpoint = Vector3(1.0, 2.0, 3.0);
function Update () {
if(character.position.y < sealevel)
character.position = spawnpoint;
}
thanks for your help i really appreciate it
– gearlive