0% found this document useful (0 votes)
54 views4 pages

Bird Script

The document contains several C# scripts for a game, including BirdScript for bird movement, PipeMoveScript for moving pipes, and PipeSpawnScript for spawning pipes at intervals. The BirdScript allows the bird to flap when the space key is pressed, while the PipeMoveScript handles the movement and deletion of pipes when they go off-screen. The PipeSpawnScript manages the spawning of pipes with a specified height offset and spawn rate.

Uploaded by

rockg2207g
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views4 pages

Bird Script

The document contains several C# scripts for a game, including BirdScript for bird movement, PipeMoveScript for moving pipes, and PipeSpawnScript for spawning pipes at intervals. The BirdScript allows the bird to flap when the space key is pressed, while the PipeMoveScript handles the movement and deletion of pipes when they go off-screen. The PipeSpawnScript manages the spawning of pipes with a specified height offset and spawn rate.

Uploaded by

rockg2207g
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

gameObject

public class BirdScript : MonoBehavior


{
// Start is called before the first frame update
void Start()
{
gameObject.name,isStatic,layer,tag = "Bird Fly";
}

// Update is called once per frame


void Update()
{

}
}

Rigidbody2D

public class BirdScript : MonoBehavior


{
public Rigidbody2D myRigidbody;
public float flapStrength;

// Start is called before the first frame update


void Start()
{
gameObject.name,isStatic,layer,tag = "Bird Fly";
}

// Update is called once per frame


void Update()
{
if (Input.GetKeyDown(KeyCode.Space) == true)
{
myRigidbody.velocity = Vector2.up * 10;
myRigidbody.velocity = Vector2.up * flapStrength;
}
}
}

PipeMoveScript

public class PipeMoveScript : MonoBehaviour


{
public float moveSpeed = 5;

// Start is called before the first frame update


void Start()
{

// Update is called once per frame


void Update()
{
transform.position = transform.position + (Vector3.left * moveSpeed) *
Time.deltaTime;
}
}

prefabricated Game object (prefab)


PipeSpawnerScript

public class PipeSpawnScript : MonoBehaviour


{
public GameObject Pipe;

// Start is called before the first frame update


void Start()
{

// Update is called once per frame


void Update()
{

{
Instantiate(Pipe, transform.position, transform.rotation);
}
}
}

public class PipeSpawnScript : MonoBehaviour


{
public GameObject Pipe;
public float spawnRate = 2;
private float timer = 0;
// Start is called before the first frame update
void Start()
{

// Update is called once per frame


void Update()
{
if (timer < spawnRate)
{
timer = timer + Time.deltaTime;
}
else
{
Instantiate(Pipe, transform.position, transform.rotation);
timer = 0;
}
}
}
public class PipeSpawnScript : MonoBehaviour
{
public GameObject Pipe;
public float spawnRate = 2;
private float timer = 0;
// Start is called before the first frame update
void Start()
{
spawnPipe();
}

// Update is called once per frame


void Update()
{
if (timer < spawnRate)
{
timer = timer + Time.deltaTime;
}
else
{
spawnPipe();
timer = 0;
}
}

void spawnPipe()
{
Instantiate(Pipe, transform.position, transform.rotation);
}
}

public class PipeSpawnScript : MonoBehaviour


{
public GameObject Pipe;
public float spawnRate = 2;
private float timer = 0;
public float heightoffset = 10;
// Start is called before the first frame update
void Start()
{
spawnPipe();
}

// Update is called once per frame


void Update()
{
if (timer < spawnRate)
{
timer = timer + Time.deltaTime;
}
else
{
spawnPipe();
timer = 0;
}
}

void spawnPipe()
{
float lowestPoint = transform.position.y - heightoffset;
float highestPoint = transform.position.y + heightoffset;

Instantiate(Pipe, new Vector3(transform.position.x,


Random.Range(lowestPoint,highestPoint),0), transform.rotation);
}
}

PipeMoveScript

public class PipeMoveScript : MonoBehaviour


{
public float moveSpeed = 5;
public float deadzone = -45;

// Start is called before the first frame update


void Start()
{

// Update is called once per frame


void Update()
{
transform.position = transform.position + (Vector3.left * moveSpeed) *
Time.deltaTime;
if (transform.position.x < deadzone)

{
Debug.Log("Pipe Deleted");
Destroy(gameObject);
}
}
}

You might also like