- Home /
Question by
joranc · Jun 21, 2015 at 11:11 AM ·
where-to-start
Flappy bird sort of game pipes goin crazy
Like you see in this video
The bottom pipes go crazy this is my script for /Pipe Init/BGloop/etc In C#
using UnityEngine; using System.Collections;
public class BGLooper : MonoBehaviour {
int numBGPanels = 6;
float pipeMax = 11.53f;
float pipeMin = 14.2f;
void Start () {
GameObject [] pipes = GameObject.FindGameObjectsWithTag("Pipe");
foreach (GameObject pipe in pipes) {
Vector3 pos = pipe.transform.position;
pos.y = Random.Range (pipeMin, pipeMax);
pipe.transform.position = pos;
}
}
void OnTriggerEnter2D(Collider2D collider) {
Debug.Log ("Triggered:" + collider.name);
float widthofBGObject = ((BoxCollider2D)collider).size.x;
Vector3 pos = collider.transform.position;
pos.x += widthofBGObject * numBGPanels;
if (collider.tag == "Pipe") {
pos.y = Random.Range (pipeMin, pipeMax);
}
collider.transform.position = pos;
}
}
Comment
How? You should write the solution you found as an answer so that others that may have the same issue can see it.
Answer by joranc · Jun 22, 2015 at 03:50 AM
i just added a 2d boxcollider and made it some what bigger and then checked "Is Trigger" then it works
Your answer
Follow this Question
Related Questions
How to find what you're looking for in the Documentation? 3 Answers
About tutorial or examples 2 Answers
Unity 3.2 Tutorial 2 Answers
I just discovered unity, How can i get started? 1 Answer
newbie question 2 Answers