Hi guys.
So I’m making a tetris-like game, and right now I have something that Instantiates blocks into a GameObject, and the GameObject moves in a direction, one unit at a time, every x time period.
Now I want to have each of those blocks to check ahead of themselves when they are supposed to move, and if there’s a block there with tag “block_stopped”, it will tag all the blocks in the object (there are always four) with “block_stopped”, and break the GameObject up.
Each block object has a SpriteRenderer and BoxCollider2D.
There are four Block GameObjects inside of an empty GameObject called p1DroppingController, and the script that controls the dropping is called p1DroppingScript.
I used a function but this function can’t be called… CheckPosForWall doesn’t autocomplete and mono doesn’t recognise that it’s there at all. Why?!
void Update () {
if (dropCount <= 1f) {
dropCount += Time.deltaTime;
} else {
dropCount -= 1f;
// check collision
foreach (Transform genericBlock in transform) {
if (CheckPosForWall(new Vector3(transform.position.x, transform.position.y + 1f, transform.position.z))) {
}
}
} else {
transform.position = new Vector3 (transform.position.x, transform.position.y+1f, transform.position.z);
}
}
}
bool CheckPosForWall (Vector3 where) {
Ray ray = Camera.main.ScreenPointToRay (where);
Debug.DrawLine(Camera.main.transform.position, Camera.main.ScreenToWorldPoint(where));
RaycastHit2D hit = Physics2D.GetRayIntersection (ray, Mathf.Infinity);
if (hit.collider != null) {
if (hit.collider.transform.tag == "block_stopped") {
Debug.Log('y');
return true;
} else
Debug.Log('n');
return false;
} else
return false;
}
Thanks guy!!!