Search Unity

CharacterShadow + broken OnMouseDown()

Discussion in 'Scripting' started by the_gnoblin, Sep 14, 2010.

  1. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
    Hello!

    I use CharacterShadow script from wiki (it creates a cam and a projector, render an outline of an object, and projects it to create a shadow which works on low end machines).

    And, well, the problem is that OnMouseDown() stops working when I use the script (I suppose that's because a cam is created and it is located in the same place as MainCamera).

    One solution is to stop using this script, the other one - to write my own OnMouseDown() implementation. Is there any third one?

    thanks
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Did you create the second camera by duplicating the main camera? If so, it is likely that it has the Main Camera tag (this is what actually identifies the camera as the main one). Try setting that tag to something else for the shadow camera.
     
  3. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
    I've noticed that OnMouseDown() doesn't work in lower left part of the screen.

    I've attached an example project with test case.

    Try clicking in "lower left" part of the screen and you won't see any messages about successful click in the console.

    Any insight into the problem would be most helpful!

    thanks :)
     

    Attached Files:

  4. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
    Please, set game vieport size to 1024x768.
    I've also attached a screenshot showing where to click to see the bug in action.
     

    Attached Files:

  5. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
    Hehe.
    The following code solves the problem:

    void Update()
    {
    child.camera.rect = new Rect(0f, 0f, 1f, 1f);
    }

    public void OnPostRender()
    {
    ...
    child.camera.rect = new Rect(0.999f, 0.999f, 0.001f, 0.001f);
    }

    Here we "spoil" the camera just before rendering ended, on the next game engine life cycle OnMouseDown is called, then in Update() we "fix" the camera so the shadow is rendered OK.