So, im trying to do a game that is just another version of flappy bird (im starting to code now), and my pipes spawn in this way:
I wanted them to spawn on the bottom line of the camera, but that doesn’t happen, how could I do that?
Spawn Pipe Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PipeSpawner : MonoBehaviour
{
public GameObject pipe;
public float spawnRate = 2;
private float timer = 0;
public float heightOffSet = 4;
// Start is called before the first frame update
void Start()
{
spawnPipe();
}
// Update is called once per frame
void Update()
{
if (timer < spawnRate)
{
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);
}
}
Pipe Movement Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PipeMovement : MonoBehaviour
{
public float moveSpeed = 5;
public float deadZone = -40;
// 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 Destroyed!");
Destroy(gameObject);
}
}
}
If im not explaining well let me know.