Im designing a side scroller rolling ball game and i need help with the code using java script. Basically what i want the ball to do is when it falls off the map it will re spawn to where the ball first spawned at. This is my first unity game and I really dont know where to get started. This is the script that i have so far. Thanks in advance!
private var dead = false;
function OnControllerColliderHit(hit : ControllerColliderHit) {
if(hit.gameObject.tag == “DEATHZONE”)
{
dead = true;
}
function LateUpdate()
{
if(dead)
{
transform.position = Vector3(0,0,0);
gameObject.Find(“Main Camera”).transform.position = Vector3(0,0,0);
dead = false;
}
}
Oh hello here. You can do this in 2 manners that I remember now:
1- Create a big collider out of the screen at the bottom, when the player touches it he dies:
2- Check if the Y position of the player is negative, if it is, kill the player
function Update()
{
if( transform.position.y < 0 )
dead = true;
}
Also about the spawn, you can copy the spawn system from the old lerpz (http://unity3d.com/gallery/demos/demo-projects) tutorial or do this:
private var startPos : Vector3;
function Start()
{
startPos = transform.position;
}
function Update()
{
if( dead == true )
{
dead = false;
transform.position = startPos;
}
}
BCE0005 is the error code we are getting … witch is an unknown identifier … Like i said we are totally lost when it comes to coding if you could go step by step it would help a lot… Its telling us that something is wrong with line 10 and is referring to “dead” … thank you so much!!
Try this one, and I think that you should find some tutorial project to help you learn more things about Unity. This error is pretty simple to solve.
private var startPos : Vector3;
private var dead : boolean;
function Start()
{
startPos = transform.position;
dead = false;
}
function Update()
{
if( transform.position.y < 0 )
{
dead = true;
}
if( dead == true )
{
dead = false;
transform.position = startPos;
}
}