Hey guys, Im making a weekend proejct. It will be a puzzle game, based on grid placing blocks. I can place them, but there is a slight problem with stacking. I need to check if the lego piece should or shouldnt go higher – aka stack like a tower.
var totalDist : float;
var actualBlock : Transform;
var blockIsPlaced : boolean = true;
var block : Transform; //one lego piece
var x : float = 0;
var y : float = 0;
function Update (){
CheckForPlacing();
GetInput();
if(!blockIsPlaced){
actualBlock.position.x = x - 2.5 * totalDist;
actualBlock.position.y = y - 1.5 * totalDist;}}
function CheckForPlacing () {
if(blockIsPlaced)
{
actualBlock = Instantiate(block, Vector3(
transform.position.x,
transform.position.y,
transform.position.z - 0.1
),transform.rotation);
actualBlock.parent = transform;
blockIsPlaced = false;}}
function GetInput (){
if(Input.GetKeyDown(KeyCode.RightArrow)){
if(x != 5){
x += 1;}}
if(Input.GetKeyDown(KeyCode.LeftArrow)){
if(x != 0){
x -= 1;}}
if(Input.GetKeyDown(KeyCode.UpArrow)){
if(y != 5){
y += 1;}}
if(Input.GetKeyDown(KeyCode.DownArrow)){
if(y != 0){
y -= 1;}}
if(Input.GetButtonDown("Jump")){
blockIsPlaced = true;}}
– David
PS: I hope that you will understand.