Playfield.cs
There are some TODOs in “Playfield.cs”.
Scroll down to the bottom to find these. We’ll be handling the first 2 of these now.
public class Playfield : MonoBehaviour
{
...
// TODO Add public function void DeleteSelectedObject()
// If there is a currently selected object, call DeleteObject() to delete it
// TODO Add public function void RotateSelectedObject(float amount)
// If there is a currently selected object, rotate that object by the amount specified
// Negative rotation values rotate the object counter-clockwise
// TODO add public function void SaveCity()
// Save the city configuration to "City.xml"
// TODO add public function void LoadCity()
// Load the city configuration to "City.xml"
// And instantiate all the objects in that file
}
Delete Objects
- Create public function
void DeleteSelectedObject() - If there is a currently selected object call DeleteObject() to delete it
- You can use
GetSelectedObject()
- You can use
- Hook up the “Canvas/DeleteObj” button to call this function on click
You should be able to delete objects from the scene now.
Double-check that this button does nothing when you have no objects selected.
Rotate Objects
- Create public function
void RotateSelectedObject(float amount)- This takes a float parameter
amount
- This takes a float parameter
- If there is a selected object, rotate that object around the Y axis by the specified amount.
- You can use
GetSelectedObject()
- You can use
- Hook up the “Canvas/RotateCCW” and “Canvas/RotateCW” buttons to call this function on click
- “RotateCW” should turn the object by 90 degrees
- “RotateCCW” should turn the object by -90 degrees
There are many ways to rotate an object.
In my opinion, the simplest is to use transform.localEulerAngles.
You can now rotate the objects.
Watch out… many of them look pretty much the same from any orientation.
That wasn’t too bad, but let’s commit and push.