I've created a parent class that I expect to have all functions related to testing if the GameObject is grounded, in water, on air, etc... given that this functions will be used by the player as well as other GameObjects. However, the child class seems not to inherit properly the functions.
The parent script it's as follows:
public class CharacterPhysic : MonoBehaviour {
[SerializeField] protected Transform groundPoints;
float grounRadius;
private void Start ()
{
whatIsGround = LayerMask.GetMask("Ground");
groundRadius = 0.01f;
}
protected bool IsGrounded()
{
Collider2D[] colliders = Physics2D.OverlapCircleAll(groundPoints.position, groundRadius, whatIsGround);
if (colliders.Length > 0)
{
return true;
}
else return false;
}
private void FixedUpdate()
{
Debug.Log(IsGrounded());
}
}
And the children script is just:
public class ErrantMove : CharacterPhysic {
private void FixedUpdate()
{
Debug.Log(IsGrounded());
}
}
When added the first script as a component to a Gameobject (after defining the grounPoint) the Debug.Log(IsGrounded()); returns TRUE
However, when added the second script as a component to the same Gameobject (after defining the grounPoint and remove the first script) the Debug.Log(IsGrounded()); returns FALSE even in the same circumstances.
I'm expecting to be able to add movement functions into the second script but this depends on the ability to test if it is grounded.