And then only to right and only to up and only down. The main idea is to scale to one direction. The problem is i'm not using the editor to add new empty gameobject or a cube. I'm using a script to create a cube and a new empty gameobject.
In the editor in the scene window i have a cube already. And in the script i'm using this cube to create/duplicate another cube and creating new empty gameobject.
I tried to work like the answer here: The solution method 2.
But this solution is using the editor and i'm using a script. What i tried so far:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Test : MonoBehaviour
{
public GameObject gameObjectToRaise;
public float raiseAmount;
public float raiseTotal = 50;
public float speed = 2;
public static bool raised = false;
public int x, z;
private List<GameObject> cubes;
private GameObject go;
public bool randomColor;
public Color[] colorChoices;
Vector3 lp;
Vector3 ls;
// Use this for initialization
void Start()
{
lp = gameObjectToRaise.transform.localPosition;
ls = gameObjectToRaise.transform.localScale;
go = new GameObject();
CreateCubes();
}
void Update()
{
if (DetectPlayer.touched == true)
{
if (raiseAmount < raiseTotal)
{
float raiseThisFrame = speed * Time.deltaTime;
if (raiseAmount + raiseThisFrame > raiseTotal)
{
raiseThisFrame = raiseTotal - raiseAmount;
}
raiseAmount += raiseThisFrame;
gameObjectToRaise.transform.localScale += new Vector3(raiseThisFrame, raiseThisFrame, 0);
go.transform.localScale += new Vector3(raiseThisFrame, raiseThisFrame, 0);
go.transform.position += Vector3.left * (speed / 2) * Time.deltaTime;
}
else
{
raised = true;
}
}
}
private List<GameObject> CreateCubes()
{
cubes = new List<GameObject>();
for (int a = 0; a < x; a++)
{
for (int b = 0; b < z; b++)
{
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
if (randomColor)
{
cube.GetComponent<Renderer>().material.color = colorChoices[Random.Range(0, (colorChoices.Length))];
}
cube.transform.position = new Vector3(lp.x - 1, lp.y, lp.z);
cube.transform.Rotate(0, 90, 0);
cubes.Add(cube);
}
}
go.transform.position = new Vector3(lp.x - 2,lp.y,lp.z);
go.transform.Rotate(0, 90, 0);
cubes[0].transform.parent = go.transform;
return cubes;
}
}
But again it's scaling the go var(New empty gameobject) on both sided left and right and i want only to the left.
In my first question it was marked as already answered but the solution in the link is when using the editor and i want to do it by script.