2

I have created a game object (Brick) and added a script (BrickScript) to it. Within this script I create a Window game object if a certain condition is satisfied. Please see code below:

if (hasWindow) {

    if (window == null) {
        window = (GameObject)Instantiate (Resources.Load ("Prefabs/OtherPrefabs/Window"), new Vector3 (transform.position.x + 0.5 * 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";
    }
}

The Brick and window game objects actually overlap a bit. I realized that when hasWindow = true (the window is created) the condition in the code below is not satisfied and other game objects don't collide with the Brick. But when hasWindow = false (the window is not created), everything seems to work well. How can I solve this?

void OnMouseDown    ()  {

    if (Input.GetMouseButtonDown(0)) {

        Debug.Log ("touch down");
        hasBeenTouched = true;
    }
}
derHugo
  • 83,094
  • 9
  • 75
  • 115
  • Maybe your box collider for the window is overlapping the box collider for the Brick? Try resizing or disabling the box collider for the window game object. – Laslos Jul 06 '17 at 19:05

0 Answers0