i want to be able to create buildings in the RTS style. here is the sequence of steps i had in mind;
1.the player clicks on the gui button associated with the building he wants to build.
2.the building(prefab) is instantiated at the mouse position.
3.the building is able to be moved around according to the mouse’s position.
4.the player clicks again and a raycast is shot.
5.the building’s postion is transformed to the postion of the “raycasthit.point”.
I am having a problem with step 3. i have no clear way in mind in approaching this problem.
please no code solutions. i want to do it myself. but i need help breaking it down. i am a complete beginner so bear with me please.
if anything is unclear in my question or you require any detail let me know.
In step 2 is the building supposed to be at the location on the terrain below (behind gui) as if step 4 is merely to finalize it’s position? if so, step 3 will also involve casting a ray and moving the prefab to that spot (perhaps with a semi-transparent material or something until it is finalised).
If this is what you are after, upon pressing the gui button, instantiate the prefab and then make a Boolean of your choosing set to true.
In step 3, during your Update (or FixedUpdate) check if the Boolean is set to true, then cast a ray from the camera to the mouse position and use the transform of the hit. Teleport the position of your prefab object to this location.
In step 4, again check for both the Boolean being set to true and a mouse-click. Then check if the spot where the raycast is suitable for your building to be placed down (perhaps using a grid system or checking that the normal of the location isn’t too steep).
Then if all that goes through move onto step 5: update the building location by teleporting it to the hit transform, then turn the Boolean off.