- Home /
Making A 2d game android
hello to all, I'm trying to make a game like this:
a 2d game in which the character runs endlessly. But I do not know how to make this thing of '"infinity." I realize the potential of prefab obstacles along the ground, and instantiate them in code, but I realized that it is terribly heavy, and I always stops to load the route. Do you have any advice for me? thanks in advance
Just instantiate cube every x seconds at the start of the screen and destroy it
when it is out of camera view
Answer by maroltl · Jan 02, 2014 at 06:58 PM
var cube : GameObject;
var position = Vector3(x,y,z);
InvokeRepeating(SpawnCube, 0.0, 2);
function SpawnCubes () {
Instantiate(cube, position, Quaternion.identity);
}
this will spawn a cube every 2 seconds at the position you enter in position variable. when I was working on same kind of game I destroy cubes when they were on colision with game object on left side out of camera view. this game object was chid to pplayer, so it stayed on same positon when the player was running.to destroy cubes check this link and this one
okey I made this code to associate with the bar that destroys:
function OnCollisionEnter(collision : Collision) {
if(collision.collider.gameObject)
{
Destroy (gameObject);
}
} but it does not work, what should I write?
function OnCollisionEnter(collision : Collision) {
Destroy (collision.gameObject);
}
Your answer
Follow this Question
Related Questions
Things to know about 2D games! 1 Answer
Drag and release 2 Answers
Terrain: Use as scenario (individual) and prefab (unchanged, reusable) 0 Answers
New/Load(Continue) in menu 1 Answer