- Create ground plane
- Scale ground plane:
(16,1,16)
- Position ground plane:
(0,-0.5,0)
- Create cube (Maybe call it "block" instead of "cube"?)
- Drag cube to Assets (to make it a "prefab")
- Create cube material in Assets
- Set material color to something like brown
- Assign material to cube prefab mesh renderer
- Save scene (and note the new scene Asset)
- Drag a couple cube prefabs into the scene
- Manually set the position coords to be integer? (e.g.,
(5,0,0)
,(-5,0,3)
,(2,0,-2)
) - Add script
MineBlock.cs
to collider for cube prefab - Implement
OnMouseDown
. JustDebug.Log
a message to console to start with. UsegameObject.name
. - Then
Destroy(gameObject);
on mouse down.
- Create Cube called ItemDrop.
- Scale it: (0.5,0.5,0.5)
- Rotate it: (15,0,5) or whatever
- Turn off shadows?
- Drag to Assets to make it a prefab
- Hide the source GameObject ItemDrop.
- Click prefab ItemDrop.
- Give it the CubeMaterial. (Or create a new material for it?)
- In MineBlock.cs, add public GameObject itemDropPrefab;
- Drag prefab to itemDropPrefab field of Cube prefab.
- OnMouseDown, Instantiate( itemDropPrefab, transform.position, itemDropPrefab.transform.rotation); // or maybe define the rotation here programmatically?
- Import FirstPersonCharacter from Standard Assets. Also import dependencies CrossPlatformInput and Utility.
- Drag FirstPersonCharacter into the scene and remove the old "Main Camera" -- the FirstPersonCharacter contains its own camera. (It is under Assets/Standard Assets/Characters/FirstPersonCharacter/Prefabs/FPSController)
- Add MouseLock.cs script to FPSController.
- Change FPSController transform.scale to (0.5,0.9,0.5) so player can fit down into a one block hole (eventually) and through a two block height passage.
- Change radius of collider from 0.5 to 1 maybe? So item collection is triggered more easily.
- Optional: Change mouse cursor to look like crosshairs:
- Create a 16x16 png image of cross hairs.
- Append .bytes extension to the file name.
- In MouseLock.cs, public TextAsset crossHairsRaw; private Texture2D crossHairs;
- In Start, crossHairs = new Texture2D(16,16); crossHairs.LoadImage(crossHairsRaw.bytes);
- In LockCursor(), Cursor.SetCursor( crossHairs, new Vector2(8,8), CursorMode.Auto);
- In UnlockCursor(), Cursor.SetCursor( null, Vector2.zero, CursorMode.Auto); (Note cursor may not change back to original when running in the Unity Game View. Build and run to test.)
- Enable Is Trigger on ItemDrop prefab.
- Change tag on FPSController to "Player".
- Add ItemDrop.cs script to ItemDrop prefab.
- In ItemDrop.cs OnTriggerEnter, if collider.tag == "Player", Destroy ItemDrop game object.
- Need FPSController to have a collider? (Does not appear so.)
- TODO: Add block to inventory. Prerequisite: Inventory mechanism...
- add a .wav file to Assets
- In MineBlock.cs, public AudioClip mineSound;
- Assign .wav file to that mineSound field in inspector.
- In MineBlock.cs OnMouseDown(), before Destroy(gameObject), AudioSource.PlayClipAtPoint( mineSound, transform.position); // Note that declaring an AudioSource object to assign the clip and then // .Play() will not work before a Destroy because the Audio will be // aborted when its game object is destroyed.
- Same as for sound effect when mining a block
- Play the clip in the OnTrigger() function.
- Click on the FPSController game object (not the prefab?)
- Adjust volume slider under the Audio Source component
- About 0.25 seems good. Basically do not want the walking sound to drown out the mining and collectin sounds.
- Add SpawnBlocks.cs script to Plane game object.
- public GameObject block;
- Drag cube prefab into block field
- Loops in Start() to Instantiate blocks in a pattern of some sort. Could be random height at each plane coord. Or a sinusoidal ripple pattern might be nice.
- Modify initial position of FPSController to be at (x,z) origin and at y value above the highest possible block at (x,z)=(0,0).
- create empty GameObject called BoxOutline (or maybe BlockOutline)
- create cube as child of empty -- call it "line"
- turn off shadows (cast and receive)
- scale line: (0.015,1,0.015)
- position it
- duplicate and position three more in that direction
- rotate, duplicate, and position for next set of four edges
- repeat for final set of four edges
- drag into Assets to make it a prefab
- create Material, color black, add to BoxOutline prefab.
- In MineBlock.cs, add public GameObject boxOutlinePrefab, private GameObject boxOutline, and Renderer[] wireFrame array.
- Drag BoxOutline prefab to the public boxOutlinePrefab field in the inspector
- In Start, instantiate the BoxOutline prefab, get the Renderers of all the children (lines/wires), and disable rendering on all of them.
- OnMouseEnter, enable rendering on all the wires
- OnMouseExit, disable rendering on all the wires
- OnMouseDown, Destroy(boxOutline);