Why is my sprite only detecting one sprite as the ground?
So I am trying to create a platformer where my cube sprite can jump between different platforms but only when grounded on a platform. I have this working on the first platform but any other platforms I create in the same way it does not. Here is the code I have:
using UnityEngine;
using System.Collections;
public class GroundHitCheck : MonoBehaviour {
bool isGrounded = false;
public Transform GroundCheck1;
public Transform GroundCheck2;
public LayerMask ground_layers;
void FixedUpdate()
{
isGrounded = Physics2D.OverlapArea(GroundCheck1.position,GroundCheck2.position,ground_layers);
Debug.Log("Grounded: "+isGrounded);
}
}
Where am I going wrong?
do the other platforms have a collider2D and are on the ground_layers? Are the GroundCheck GameObjects attached to the player?
Answer by hexagonius · Aug 28, 2015 at 08:03 PM
If there are three platforms in the scene and you start the game with the player on a different platform every time (move to different one in editor), does it work with the one you're starting on? Or is it just one platform it is working with? first case, is the script toggled at some point? second case, are the platforms really identical?
It only works on one platform no matter where I move the sprite.