Sorry for my bad english.
I’ve created a parent class that I expect to have all functions related to test 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 beig 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 component to a gameobject (after define the grounPoint) the Debug.Log(IsGrounded());
returns TRUE
However, when added the second script as component to the same gameobject (after define 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 depend on the ability to test if it is grounded.