Search Unity

SignCollision2D

Discussion in '2D' started by WintermuteDigital, Dec 31, 2014.

  1. WintermuteDigital

    WintermuteDigital

    Joined:
    Dec 4, 2014
    Posts:
    19
    I want to have a sign in my scene and I have it set to a box collider with Is Trigger as true, but I have no idea how to access the OnCollisionStay2d for C# in Monodevelop. The idea is that I have a canvas with text on it, and I want to set the opacity to 255 when the player is inside the collider, I won't LERP it, because that's unnecessary. I'd appreciate some help. Thanks guys!

    Also, I've checked the Documentation, but it's not really that helpful. I'm not experienced. Heck I'm 13.
     
  2. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    make tag for player Player. Then c# script for sign

    void OnTriggerStay2D (Collider2D other) {
    if (other.gameObject.tag == "Player")
    //here something what you want
    ;}
     
  3. WintermuteDigital

    WintermuteDigital

    Joined:
    Dec 4, 2014
    Posts:
    19
    Thanks! That's really helpful. :) But now, I've got the error which I can't use void in front of OnTriggerStay2d: I get this error:
    Assets/Scripts/Visiblity.cs(9,20): error CS1519: Unexpected symbol `void' in class, struct, or interface member declaration
    I'm not really sure about how to fix this. "Return OnTriggerStay2D" or anything. I can't figure out these return types. Help please!
     
    Last edited: Dec 31, 2014
  4. WintermuteDigital

    WintermuteDigital

    Joined:
    Dec 4, 2014
    Posts:
    19
    NVM I'm being dumb. Forgot semicolon.