Hello!
Im trying to rotate everything inside an array. I have this code, what needs tweaking?
using UnityEngine;
using System.Collections;
public class Rotation : MonoBehaviour {
public GameObject[] blocksOnLevel;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
blocksOnLevel = GameObject.FindGameObjectsWithTag("Blocks");
}
public void turnLeft ()
{
foreach(GameObject go in blocksOnLevel)
{
transform.Rotate(Vector3.left * Time.deltaTime);
}
print("Im working");
}
}
Hi,
you are not calling your turn function and also you are looking for all your objects every frame (update) which is too heavy and will hurt your performance.
Try this:
using UnityEngine;
using System.Collections;
public class Rotation : MonoBehaviour {
public GameObject[] blocksOnLevel;
public bool turnBlocks;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(turnBlocks == true) turnLeft();
}
public void turnLeft ()
{
blocksOnLevel = GameObject.FindGameObjectsWithTag("Blocks");
foreach(GameObject go in blocksOnLevel)
{
transform.Rotate(Vector3.left * Time.deltaTime);
}
print("Im working");
}
}
then change your boolean via a game event, a button or something.
Hope that helps,