Hi !
Being a total beginner with Unity I was trying to follow some tutorials to learn how to use it, and found one which I find good for making a RTS in RTS Tutorial
My trouble is that it was written 2 years ago and, having a technical issue, I was not able to contact the autor, so I was wondering if anyone could be able to help me out of this.
To try and make it simple, one of the first step of the tutorials guide us on how to make a HUD which should display, among other things, the name of the elements of the scene we click on, granted we have attached a script on these elements and assigned a name to them.
Which work fine when I try and build some simple objects like an assemblage of 3D cube like depicted in the tutorial, but if I try to import some more complex buildings frome the store, like in my case : “Medieval fantasy house by robin tucker” and attach the script to them / set up a name, nothing happen when I click on it …
Here is the code who handle the click, if it’s of any help :
private void LeftMouseClick() {
if(player.hud.MouseInBounds()) {
GameObject hitObject = FindHitObject();
Vector3 hitPoint = FindHitPoint();
if(hitObject && hitPoint != ResourceManager.InvalidPosition) {
if(player.SelectedObject) player.SelectedObject.MouseClick(hitObject, hitPoint, player);
else if(hitObject.name!="Ground") {
WorldObject worldObject = hitObject.transform.root.GetComponent< WorldObject >();
if(worldObject) {
//we already know the player has no selected object
player.SelectedObject = worldObject;
worldObject.SetSelection(true);
}
}
}
}
}
And the two functions :
private GameObject FindHitObject() {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, out hit)) return hit.collider.gameObject;
return null;
}
private Vector3 FindHitPoint() {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, out hit)) return hit.point;
return ResourceManager.InvalidPosition;
}
So I guess my problem lies in the Raycasthit, but I’m unable to find out why.
I then progressed a good bit in the tutorial, thinking that maybe something in the end would explain my problem, but to no avail.
I appreciate any help, and sorry if that’s not very clear, english isn’t my natural language.