I have a problem.
I used this code which I found somewhere here in the forums…it’s a raycasting method for clicking objects.
`
script ExecuteInEditMode
var gSkin : GUISkin;
var backdrop : Texture2D;
var target1: Transform;
var target2: Transform;
private var isLoading = false;
function OnGUI()
{
if (gSkin)
GUI.skin = gSkin;
else
Debug.Log("StartMenuGUI: GUI Skin object missing!");
var backgroundStyle : GUIStyle = new GUIStyle();
backgroundStyle.normal.background = backdrop;
GUI.Label(Rect((Screen.width - (Screen.height *2)) *0.75,0,Screen.height *2,
Screen.height ),"",backgroundStyle);
//Loading Screen
if (isLoading)
Application .LoadLevel("Rotating Arch");
}
function Update () {
if (Input.GetMouseButton(0)) {
var ray: Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit: RaycastHit;
if (Physics.Raycast(ray, hit)) {
if (hit.transform == target1) {
print("Hit target 1");
isLoading = true;
} else if (hit.transform == target2) {
print("Hit target 2");
}
} else {
print("Hit nothing");
}
}
}`
Anyway…
This works fine for those buildings that have single meshes.
But sometimes when the model has multiple meshes…I choose the one that covers all parts of the model(that’s where I put my collider) then test if it will take a “hit”.
Apparently…it does not work.
NOTE: in the code sample there are 2 targets only. Because I test the buildings 1 by 1 first to know if I put the colliders in the right mesh.
But in the long run…once I have all colliders in the right place I will have multiple targets.
The goal is to make each building “clickable” so that when it is “hit” it will go to a scene where it’s details are shown.
The problem is that Multiple Meshed models seem to not work for this code.
I need to fix this asap for this is part of my thesis XD
Did I do something wrong?
Is there any other alternative for this kind of thing?
ANOTHER NOTE: I attach the above script to an FPS Controller. This is part of a “Free Roam” function of my thesis. More of a digital tour of a place