Skip to main content
3 of 3
Reworded the title.
Vaillancourt
  • 16.4k
  • 17
  • 55
  • 61

Why aren't my walls moving, and how do I make them move?

Here is my all GameControl script:

static GameObject HexGrey;
static GameObject HexPurple;
static GameObject HexBlue;
static GameObject HexGreen;
static GameObject HexTurq;
static GameObject HexRed;
static GameObject HexYellow;

Vector3 GreyVec;
Vector3 PurpleVec;
Vector3 BlueVec;
Vector3 GreenVec;
Vector3 TurqVec;
Vector3 RedVec;
Vector3 YellowVec;
Vector3 GreyVecOrigin;
Vector3 PurpleVecOrigin;
Vector3 BlueVecOrigin;
Vector3 GreenVecOrigin;
Vector3 TurqVecOrigin;
Vector3 RedVecOrigin;
Vector3 YellowVecOrigin;

public Button button;                       // DeathCanvas
public Text text;

public Material wallMat;

float t;

public static int a = 0;
public static int b = 0;
float wallMoveT = 0.7f;

private IEnumerator coroutine;

void Start()
{
    button.gameObject.SetActive(false);         // DeathCanvas
    text.enabled = false;
    coroutine = enumerator(3);
    StartCoroutine(coroutine);
    ObjectAssignment();
    VecAssignment();
}

void Update()
{
    WallControl();
}

void ObjectAssignment()
{
    HexGrey = GameObject.FindGameObjectWithTag("HexGrey");
    HexPurple = GameObject.FindGameObjectWithTag("HexPurple");
    HexBlue = GameObject.FindGameObjectWithTag("HexBlue");
    HexGreen = GameObject.FindGameObjectWithTag("HexGreen");
    HexTurq = GameObject.FindGameObjectWithTag("HexLBlue");
    HexRed = GameObject.FindGameObjectWithTag("HexRed");
    HexYellow = GameObject.FindGameObjectWithTag("HexYellow");
}

void VecAssignment()
{
    t += Time.deltaTime / wallMoveT;

    GreyVecOrigin = new Vector3(HexGrey.transform.position.x, 0, HexGrey.transform.position.z);
    PurpleVecOrigin = new Vector3(HexPurple.transform.position.x, 0, HexPurple.transform.position.z);
    BlueVecOrigin = new Vector3(HexBlue.transform.position.x, 0, HexBlue.transform.position.z);
    GreenVecOrigin = new Vector3(HexGreen.transform.position.x, 0, HexGreen.transform.position.z);
    TurqVecOrigin = new Vector3(HexTurq.transform.position.x, 0, HexTurq.transform.position.z);
    RedVecOrigin = new Vector3(HexRed.transform.position.x, 0, HexRed.transform.position.z);
    YellowVecOrigin = new Vector3(HexYellow.transform.position.x, 0, HexYellow.transform.position.z);

    GreyVec = new Vector3(HexGrey.transform.position.x, -4, HexGrey.transform.position.z);
    PurpleVec = new Vector3(HexPurple.transform.position.x, -4, HexPurple.transform.position.z);
    BlueVec = new Vector3(HexBlue.transform.position.x, -4, HexBlue.transform.position.z);
    GreenVec = new Vector3(HexGreen.transform.position.x, -4, HexGreen.transform.position.z);
    TurqVec = new Vector3(HexTurq.transform.position.x, -4, HexTurq.transform.position.z);
    RedVec = new Vector3(HexRed.transform.position.x, -4, HexRed.transform.position.z);
    YellowVec = new Vector3(HexYellow.transform.position.x, -4, HexYellow.transform.position.z);
}

void WallControl()
{
    if (a == 1)
    {
        wallMat.color = Color.grey;
        if (b == 1)
        {
            HexPurple.transform.position = Vector3.Lerp((HexPurple.transform.position), (PurpleVec), t);
            HexBlue.transform.position = Vector3.Lerp((HexBlue.transform.position), (BlueVec), t);
            HexGreen.transform.position = Vector3.Lerp((HexGreen.transform.position), (GreenVec), t);
            HexTurq.transform.position = Vector3.Lerp((HexTurq.transform.position), (TurqVec), t);
            HexRed.transform.position = Vector3.Lerp((HexRed.transform.position), (RedVec), t);
            HexYellow.transform.position = Vector3.Lerp((HexYellow.transform.position), (YellowVec), t);
            Debug.Log("GREY");
        }
    }
    else if (a == 2)
    {
        wallMat.color = Color.magenta;
        if (b == 2)
        {
            HexGrey.transform.position = Vector3.Lerp((HexGrey.transform.position), (GreyVec), t);
            HexBlue.transform.position = Vector3.Lerp((HexBlue.transform.position), (BlueVec), t);
            HexGreen.transform.position = Vector3.Lerp((HexGreen.transform.position), (GreenVec), t);
            HexTurq.transform.position = Vector3.Lerp((HexTurq.transform.position), (TurqVec), t);
            HexRed.transform.position = Vector3.Lerp((HexRed.transform.position), (RedVec), t);
            HexYellow.transform.position = Vector3.Lerp((HexYellow.transform.position), (YellowVec), t);
            Debug.Log("MAGENTA");
        }
    }
    else if (a == 3)
    {
        wallMat.color = Color.blue;
        if (b == 3)
        {
            HexPurple.transform.position = Vector3.Lerp((HexPurple.transform.position), (PurpleVec), t);
            HexGrey.transform.position = Vector3.Lerp((HexGrey.transform.position), (GreyVec), t);
            HexGreen.transform.position = Vector3.Lerp((HexGreen.transform.position), (GreenVec), t);
            HexTurq.transform.position = Vector3.Lerp((HexTurq.transform.position), (TurqVec), t);
            HexRed.transform.position = Vector3.Lerp((HexRed.transform.position), (RedVec), t);
            HexYellow.transform.position = Vector3.Lerp((HexYellow.transform.position), (YellowVec), t);
            Debug.Log("BLUE");
        }
    }
    else if (a == 4)
    {
        wallMat.color = Color.green;
        if (b == 4)
        {
            HexPurple.transform.position = Vector3.Lerp((HexPurple.transform.position), (PurpleVec), t);
            HexBlue.transform.position = Vector3.Lerp((HexBlue.transform.position), (BlueVec), t);
            HexGrey.transform.position = Vector3.Lerp((HexGrey.transform.position), (GreyVec), t);
            HexTurq.transform.position = Vector3.Lerp((HexTurq.transform.position), (TurqVec), t);
            HexRed.transform.position = Vector3.Lerp((HexRed.transform.position), (RedVec), t);
            HexYellow.transform.position = Vector3.Lerp((HexYellow.transform.position), (YellowVec), t);
            Debug.Log("GREEN");
        }
    }
    else if (a == 5)
    {
        wallMat.color = Color.cyan;
        if (b == 5)
        {
            HexPurple.transform.position = Vector3.Lerp((HexPurple.transform.position), (PurpleVec), t);
            HexBlue.transform.position = Vector3.Lerp((HexBlue.transform.position), (BlueVec), t);
            HexGreen.transform.position = Vector3.Lerp((HexGreen.transform.position), (GreenVec), t);
            HexGrey.transform.position = Vector3.Lerp((HexGrey.transform.position), (GreyVec), t);
            HexRed.transform.position = Vector3.Lerp((HexRed.transform.position), (RedVec), t);
            HexYellow.transform.position = Vector3.Lerp((HexYellow.transform.position), (YellowVec), t);
            Debug.Log("CYAN");
        }
    }
    else if (a == 6)
    {
        wallMat.color = Color.red;
        if (b == 6)
        {
            HexPurple.transform.position = Vector3.Lerp((HexPurple.transform.position), (PurpleVec), t);
            HexBlue.transform.position = Vector3.Lerp((HexBlue.transform.position), (BlueVec), t);
            HexGreen.transform.position = Vector3.Lerp((HexGreen.transform.position), (GreenVec), t);
            HexTurq.transform.position = Vector3.Lerp((HexTurq.transform.position), (TurqVec), t);
            HexGrey.transform.position = Vector3.Lerp((HexGrey.transform.position), (GreyVec), t);
            HexYellow.transform.position = Vector3.Lerp((HexYellow.transform.position), (YellowVec), t);
            Debug.Log("RED");
        }
    }
    else if (a == 7)
    {
        wallMat.color = Color.yellow;
        if (b == 7)
        {
            HexPurple.transform.position = Vector3.Lerp((HexPurple.transform.position), (PurpleVec), t);
            HexBlue.transform.position = Vector3.Lerp((HexBlue.transform.position), (BlueVec), t);
            HexGreen.transform.position = Vector3.Lerp((HexGreen.transform.position), (GreenVec), t);
            HexTurq.transform.position = Vector3.Lerp((HexTurq.transform.position), (TurqVec), t);
            HexRed.transform.position = Vector3.Lerp((HexRed.transform.position), (RedVec), t);
            HexGrey.transform.position = Vector3.Lerp((HexGrey.transform.position), (GreyVec), t);
            Debug.Log("YELLOW");
        }
    }
    else if (a == 8)
    {
        wallMat.color = Color.black;
        HexGrey.transform.position = Vector3.Lerp((HexGrey.transform.position), (GreyVecOrigin), t);
        HexPurple.transform.position = Vector3.Lerp((HexPurple.transform.position), (PurpleVecOrigin), t);
        HexBlue.transform.position = Vector3.Lerp((HexBlue.transform.position), (BlueVecOrigin), t);
        HexGreen.transform.position = Vector3.Lerp((HexGreen.transform.position), (GreenVecOrigin), t);
        HexTurq.transform.position = Vector3.Lerp((HexTurq.transform.position), (TurqVecOrigin), t);
        HexRed.transform.position = Vector3.Lerp((HexRed.transform.position), (RedVecOrigin), t);
        HexYellow.transform.position = Vector3.Lerp((HexYellow.transform.position), (YellowVecOrigin), t);
        Debug.Log("BLACK");
    }
    else
    {
        wallMat.color = Color.black;
    }
}

private IEnumerator enumerator(int waitTime)
{
    while (true)
    {
        yield return new WaitForSeconds(waitTime);
        a = Random.Range(1, 8);
        yield return new WaitForSeconds(1.5f);
        b = a;
        yield return new WaitForSeconds(waitTime);
        a = 8;
        b = 0;
    }
}

public void GoToMainMenu()
{
    SceneManager.LoadScene("MainMenu");
}

I know using integers named "a" and "b" looks like complicated, but infact it's not. First a pick random int inRange 1-8 (and color of the walls changes), then waits for 1.5f seconds and i say "b = a" (hexs' transform.position changes).

I've checked the a and b integers but the values are right.

What I want: first change the color of the walls randomly. Then wait 1.5f seconds and transform the objects according to walls' color. And loop this cycle.

Problem is: Color of the walls changes but objects positions never change.