Hi I am new at Unity and I am trying to create a rubiks cube application.
I recently hit a road block which is I can’t seem to rotate the cube pieces.
As you can see I want to rotate the cubes as one but they don’t seem to respond at all
This is the code I am using:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cube : MonoBehaviour {
public GameObject rubix;
private GameObject[] cube;
private GameObject[] face;
private GameObject rightPivot;
private int i;
void Start()
{
cube = GameObject.FindGameObjectsWithTag("cube");
face = new GameObject[9];
RotateRight();
}
void RotateRight()
{
i = 0;
rightPivot = new GameObject("rightPivot");
rightPivot.transform.position = new Vector3(2, 1, 1);
rightPivot.transform.parent = rubix.transform;
foreach (GameObject cube in cube)
{
if (cube.transform.position.x == 2)
{
cube.transform.parent = rightPivot.transform;
cube.name = "Right Face Cube";
face *= cube;*
i++;
}
}
}
void Update()
{
rightPivot.transform.RotateAround(rightPivot.transform.position, Vector3.right, Time.deltaTime);
}
}