Hey guys, I’m somewhat new to using Unity and I need to get a bunch of still images of the objects I’m using in my environment from different angles.
Some details: I have a game object hierarchy that I’ve preserved for filenaming purposes:
Level 1. Objects (parent) - I’ve attached the script here.
Level 2. Object subclasses (children) - again, to organize classes for filenaming.
Level 3. Objects (grandchildren) - the actual objects I need images of.
So, I am looping through the children, then through the grandchildren, moving each grandchild to a predetermined location that the camera is looking at. Once at that location, I rotate the object the appropriate angle in a for loop and take a screenshot. I then rotate it back to its original rotation (0,0,0) each iteration. After the rotation loop executes I then move the object back to its original position and then go to the next object.
The main problem I am having is that it doesn’t seem to be looping through each item and taking a screenshot. It appears as if it will loop through everything and then take one screenshot at the end instead of taking a screenshot every iteration. Essentially, what I end up with is a picture of a blank screen, because the objects have all been moved into the camera view and then returned to their original position before the camera even does a screen capture…
Any assistance would be greatly appreciated!
Code:
var seatPos : Vector3;
function Start () {
var nSubTypes = transform.childCount;
// Loop through object subtypes
for (var i : int = 0; i < nSubTypes; i++) {
var Child = transform.GetChild(i);
var nChildren = Child.childCount;
// Loop through each subobject
for (var j : int = 0; j < nChildren; j++) {
// Save original position
var origPos = Child.GetChild(j).transform.position;
// Move to camera position
Child.GetChild(j).transform.position = seatPos;
// Make array of camera angles
var angles = new Array();
angles[0] = -90;
angles[1] = -60;
angles[2] = -30;
angles[3] = 0;
angles[4] = 30;
angles[5] = 60;
angles[6] = 90;
var nAngles = angles.length;
for (var k : int = 0; k < nAngles; k++) {
// Make filename
var str = "Screenshots/ScreenshotTest_" + Child.name + "_" + Child.GetChild(j).name + "_" + angles[k] + ".png";
// Rotate
Child.GetChild(j).transform.Rotate(0,angles[k],0);
// Screenshot
Application.CaptureScreenshot(str,5);
Debug.Log(Child.GetChild(j).name + " angle " + angles[k] + " captured...");
// Rotate back
Child.GetChild(j).transform.Rotate(0,0,0);
WaitForSeconds(3);
}
// Move to original position
Child.GetChild(j).transform.position = origPos;
}
}
}