Skip to main content
Post Undeleted by Justin Markwell
added 253 characters in body
Source Link
Justin Markwell
  • 2.2k
  • 2
  • 14
  • 16

you need to make sureIt looks like the gameobjectoverlapping is causing your issue since the collider will be already colliding with the window that. You can solve this problem a couple ways. you instantiate also hascan create a collidernew layer and you will call your OnMouseDown() fromset the window scriptobject to that layer. then in physics 2d settings you can set the collision matrix to not collide with each other. Or you can possibly set the windows z position to be in a spot that wont collide.

you need to make sure the gameobject window that you instantiate also has a collider and you will call your OnMouseDown() from the window script.

It looks like the overlapping is causing your issue since the collider will be already colliding with the window. You can solve this problem a couple ways. you can create a new layer and set the window object to that layer. then in physics 2d settings you can set the collision matrix to not collide with each other. Or you can possibly set the windows z position to be in a spot that wont collide.

Post Deleted by Justin Markwell
deleted 615 characters in body
Source Link
Justin Markwell
  • 2.2k
  • 2
  • 14
  • 16

you are asking if hasWindow when there is no window soneed to make sure the gameobject window that you instantiate is not firing properly.also has a collider and you can either change it to hasBeenTouched or set the hasWindow bool to true in thewill call your OnMouseDown for it to fire() from the window script.

 if (hasBeenTouched)
    {

        if (window == null)
        {
            window = (GameObject)Instantiate(Resources.Load("Prefabs/OtherPrefabs/Window"),
                new Vector3(transform.position.x + 0.5f * gameObject.GetComponent<SpriteRenderer>().bounds.size.x, transform.position.y + 0.5f * gameObject.GetComponent<SpriteRenderer>().bounds.size.y, transform.position.z),
                Quaternion.identity);
            window.name = gameObject.name + "Window";
        }
    }

you are asking if hasWindow when there is no window so the instantiate is not firing properly. you can either change it to hasBeenTouched or set the hasWindow bool to true in the OnMouseDown for it to fire.

 if (hasBeenTouched)
    {

        if (window == null)
        {
            window = (GameObject)Instantiate(Resources.Load("Prefabs/OtherPrefabs/Window"),
                new Vector3(transform.position.x + 0.5f * gameObject.GetComponent<SpriteRenderer>().bounds.size.x, transform.position.y + 0.5f * gameObject.GetComponent<SpriteRenderer>().bounds.size.y, transform.position.z),
                Quaternion.identity);
            window.name = gameObject.name + "Window";
        }
    }

you need to make sure the gameobject window that you instantiate also has a collider and you will call your OnMouseDown() from the window script.

Source Link
Justin Markwell
  • 2.2k
  • 2
  • 14
  • 16

you are asking if hasWindow when there is no window so the instantiate is not firing properly. you can either change it to hasBeenTouched or set the hasWindow bool to true in the OnMouseDown for it to fire.

 if (hasBeenTouched)
    {

        if (window == null)
        {
            window = (GameObject)Instantiate(Resources.Load("Prefabs/OtherPrefabs/Window"),
                new Vector3(transform.position.x + 0.5f * gameObject.GetComponent<SpriteRenderer>().bounds.size.x, transform.position.y + 0.5f * gameObject.GetComponent<SpriteRenderer>().bounds.size.y, transform.position.z),
                Quaternion.identity);
            window.name = gameObject.name + "Window";
        }
    }