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

My Javascript function is not working. I'm new to this!

Discussion in 'Scripting' started by Standard_Joe, Aug 23, 2014.

  1. Standard_Joe

    Standard_Joe

    Joined:
    Jul 3, 2014
    Posts:
    2
    function respawnWaitTime ()
    {
    renderer.enabled = false;
    RandomColor ();
    yield WaitForSeconds (respawnWaitTime);
    renderer.enabled = true;
    }

    This is a function I'm trying to use to make a shape vanish and change color, and then come back. But I get an error message asking for a semicolon at the end, or a parenthesis before the name. And if I do these things, I get even more errors because that's not a function looks. Can anybody tell me what's wrong with it? I'm brand new to programming.
     
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    I don't see anything wrong with the snippet you posted. You'll want to post the rest of the script (using code tags) along with the full error message to get more help.
     
  3. Lahzar

    Lahzar

    Joined:
    May 6, 2013
    Posts:
    87
    @DanielQuick is right, you should post entire code (with codetags: http://forum.unity3d.com/threads/using-code-tags-properly.143875/) and error, but I think this error is because you cannot have a variable have the same name as a function or the script itself. If thats not the case, it could be that you need to put your WaitForSeconds yield in an IEnumerator.

    Also post this in awnsers section, not forum D:
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It already is.

    No, here is fine. Cross-posting is not encouraged.

    --Eric
     
    Lahzar likes this.