Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

SignCollision2D

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

  1. Jay2001

    Jay2001

    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. Jay2001

    Jay2001

    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. Jay2001

    Jay2001

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