I have 2 scripts, CollisionDetector.cs and PlayerMovement.cs. The way I am doing the movement, I need to create collisions separately. I am currently doing this by drawing Raycasts on each of the 4 sides of the player (I am doing top-down movement), and trying to make the player detect where is an appropriate spot to move. But when referencing the hitInfo variables in another script, it returns a NullReferenceException (to all sides of the player). I have checked the values and they are not null. Any help here?
Thanks.
PlayerMovement.cs (A bit of it):
if (collisionDetector.hitInfoD.collider == null && collisionDetector.hitInfoU.collider == null &&
collisionDetector.hitInfoR.collider == null && collisionDetector.hitInfoL.collider == null) // Check if there is nothing in the way. Then the player can move free.
{
Debug.Log("help me I'm not seeing this message");
transform.position = Vector3.Lerp(startPosition, endPosition, t);
yield return null;
}
if(endPosition != collisionDetector.hitInfoD.collider.transform.position) // If the endPosition is in the collider, restrict movement to there.
{
transform.position = Vector3.Lerp(startPosition, endPosition, t);
}
yield return null;