Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

set standard material

Discussion in 'Scripting' started by paco, Nov 19, 2010.

  1. paco

    paco

    Guest

    Joined:
    Oct 28, 2010
    Posts:
    20
    hey,

    i'm trying to set the standard material for an object,
    after i changed the color in runtime.

    the code i'm using:
    myObject.renderer.material.color = Color(1,1,1,0.5);

    my problem is, after doing this, the function onMouseEnter/onMouseExit/onMouseOver,
    don't work properly anymore.

    the documentation on MonoBehaviour.OnMouseOver says the following:
    This function is not called on objects that belong to Ignore Raycast layer.

    my question, how do i set the standard material properly,
    so that the named above functions still work properly?
    (tryed a lot of different things..)

    greetz and thx
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Setting the material's color doesn't stop OnMouseEnter etc. functions from working. You're doing something else in your code that's causing it.

    --Eric
     
  3. paco

    paco

    Guest

    Joined:
    Oct 28, 2010
    Posts:
    20
    mmh. i don't think so, 'cause it works fine the whole time!
    until i reset the color anyways..

    i just wan't to reset everything to default after a given time or after
    my logic has been reached.

    here's the code that works fine till the other code (see underneath) is executed:
    PHP:
    function OnMouseEnter () {
        if( 
    onStart.debug == true ) {
            
    renderer.material.color -= renderer.material.color 2;
        }
    }
    here's the code that resets the cube's color or material after a given time:

    PHP:
    GameObject.Find"Cube1" ).renderer.material.color  Color(1,1,1,0.5);
    like i said, everything works fine, until i set the materials color back to default.
    after that everything behaves differently.
    not the way it behaved on programm start.

    (on start the color switches from "black" to "gray" - after resetting the color, it just
    changes/switches the color for 1 frame or something like that.)

    that's why my question was, how to just reset the whole material/shader to it's
    default the proper way.
    maybe i'm missing something..

    all i wan't to reach is, that a cube switches it's color from gray to black or whatever,
    when you hover/enter it with the mouse.
    after my logic is reached, i would like to set everything back to default,
    so you can start all over again.

    greetz thx
     
  4. pakfront

    pakfront

    Joined:
    Oct 6, 2010
    Posts:
    551
    Is it causing 'object is null' errors? That will often break things that seem unrelated as it interrupts code execution.
     
  5. paco

    paco

    Guest

    Joined:
    Oct 28, 2010
    Posts:
    20
    sorry. nevermind. *gg*
    it's like magic. ;)
    problem just ain't there no more.
    thx! :)