RTS like development help
Hi, im doing a project for college with the theme "social network". But social network is so bland for my taste, so i thought i could "spice" things up with a rts like game that would be influenced by the number of "likes/dislikes" of posts. The web part is more or less finished but since i never programed in c# before im kinda in a pinch. how do i make a clickable building that would trigger a ingame window with the building stats? Thanks in advance
Answer by Soos621 · May 31, 2016 at 08:13 PM
You want to do something like this
Public Camera playerCam;
void Update (){ If(Input.GetMouseDown(0)){ OnMouseClick (); } }
void OnMouseClick (){ RaycastHit camRayHit; If(Physics.Raycast(playerCam.transform.position, playerCam.transform.forward, out camRayHit, 1000)){ If(camRayHit.collider != Null){ If(camRayHit.collider.GetComponent()){ //Hit object is building } } } }
I apologize for the format I am on a mobile device
Thank you, but in what object should i attatch this script to? camera or the building?
What I usually do is attach the script to the players gmeobject and then just have a reference to the camera but if the player object is the camera then that's fine too
The game will be a isometric rts like game with no character, like travian where the player can click the buildings to upgrade them. So thenobjdctive would be on building click to popup a window with the building stats and upgrade cost.
ok then. I would also suggest looking into interfaces it will allow you to click different objects without having to re-code scripts (Example: if you have units and buildings that you wanted clicked you can use a interface to make them both "clickable") just food for thought