I have never come across this before, and there are probably alternative ways to deal with this, but here goes -
I have a SpaceShip, over a platform (A modified Cube Primitive). I am using the “Water” from the Standard Assets, so underneath that there is a plane to “hit”, when the platform is not below. Thus I want to detect whether it is a Platform, or over the “seabed” (Tagged as “Base” in code") -
void Update () {
if (OverPlatform())
isAbovePlatform = true;
else
isAbovePlatform = false;
}
bool OverPlatform()
{
RaycastHit hit;
bool abovePlatform = false;
if (Physics.Raycast(transform.position, -Vector3.up, out hit))
{
if (hit.transform.gameObject.tag.Equals(“Platform”))
{
Debug.Log(“Platform hit”);
abovePlatform = true;
}
else
{
Debug.Log(“base hit”);
abovePlatform = false;
}
}
return abovePlatform;
}
My problem is that when the ship is above the platform, on each iteration of Update(), it is alternating between the platform and the base, surely the platform, as the first object underneath, would be found first every time ?
