Does anyone know how to stop your player from jumping when you click on an object? I have a ball that can jump over obstacles and I want it to not jump when I have clicked on a door to destroy it.
Player script:
void Update() {
grounded = Physics2D.IsTouchingLayers(col, layerGround);
if (Input.GetMouseButton(0) && grounded && !gameOver && started) {
if (speed > 0) {
if (OpenDoor.instance.isDoorOpen == false) {
rb.velocity = new Vector2(rb.velocity.x, jumpSpeed);
}
}
}
}
Door script:
public class OpenDoor : MonoBehaviour {
public static OpenDoor instance;
public bool isDoorOpen;
void Awake() {
if (instance == null) {
instance = this;
}
}
// Use this for initialization
void Start () {
isDoorOpen = false;
}
// Update is called once per frame
void Update () {
}
public void OnMouseDown() {
//doorOpen.SetActive(true);
Destroy(gameObject);
isDoorOpen = true;
}
}