Hey i want to Stop Raycasting when it hits a GuiTexture (if you touch / hit a GUI Element do not raycast or stop casting). Already tryed some stuff with Tags and Layers without any luck, hope someone can help me out.
GuiTextures are created with the Editor, not code (just moved and modified by code).
Raycast Code:
if (Input.GetKeyUp(KeyCode.Mouse0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
Debug.Log(hit.point);
Collider[] colliders = Physics.OverlapSphere(hit.point, explosionRadius);
foreach(Collider c in colliders)
{
if (c.rigidbody == null) continue;
c.rigidbody.AddExplosionForce(explosionForce, hit.point, explosionRadius, upMod, ForceMode.Impulse);
}
}
You cannot use a Raycast() with a GUITexture. What you can do is use GUITexture.HitTest() to test if you’ve hit a specific texture. Or, you could create world colliders that tracks each GUITexture. To make the collider work, you’ll need to convert the viewport position of the GUITexture to a world position. That can be done using Camera.ViewportToWorldPoint().
You could use the z position and get the greatest gui to do touch events on.
float fZhight;
int iSaveHighZ;
AddGuiButton[] AllGuiTextures;
void DoTouchOnGuiTextures()
{
AllGuiTextures = FindObjectsOfType<AddGuiButton>();
if(AllGuiTextures.Length != 0)
{
//Get closest z high
fZhight = -2;
iSaveHighZ = -2;
for(int l = MyFuncs.Zero; l < AllGuiTextures.Length; l++)
{
if(AllGuiTextures[l])
if(Input.touchCount != MyFuncs.Zero)
{
if(AllGuiTextures[l].thisGuiTexture.HitTest((Vector3)Input.touches[0].position))
{
if(fZhight < AllGuiTextures[l].tMyTran.position.z)
{
fZhight = AllGuiTextures[l].tMyTran.position.z;
iSaveHighZ = l;
}
//Set the trigger for button touch
if(!RootLink.InputControlMgrLink.isTouchingScreenBtn)
RootLink.InputControlMgrLink.isTouchingScreenBtn = !RootLink.InputControlMgrLink.isTouchingScreenBtn;
}//Hit True
}
else
{
//Reset
AllGuiTextures[l].SetupTexture(0);
}//Amount of Touches
}//loop end textures
//do or action / press or hold
if(AllGuiTextures[iSaveHighZ] && Input.touchCount != MyFuncs.Zero)
AllGuiTextures[iSaveHighZ].touchUnity(0);
}
}