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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

does anyone know how to fix this

Discussion in 'Scripting' started by Deleted User, Aug 31, 2018.

Thread Status:
Not open for further replies.
  1. Deleted User

    Deleted User

    Guest

    protected Vector2 GetLocationInsideLevel()
    {
    return new Vector2 (UnityEngine.Random.Range (originOfLevel.x + maxObstacleRadius, originOfLevel.x + size.x - maxObstacleRadius),
    UnityEngine.Range (originOfLevel.y + maxObstacleRadius, originOfLevel.y + size.y - maxObstacleRadius));
    }
    For this one I get an error message saying "the name size does not exist in the current context"

    PlaceFirstObstacle();

    while (NumberOfObstacles >= 0) {
    yield return delay;
    if(PlaceNextObstacle()) NumberOfObstacles--;

    }
    and for this one it says "the name PlaceNextObstacle does not exist in the current context"
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,558
    First fix would be putting in code tag, so easier easier to read.

    Is this your code?
    Size is a vector in your case. It expects vector either in method or as global variable, outside method. Which probably don't exists.

    Second part is taken out of full contexts, or PlaceNextObstacle () don't exists. Check spelling.
     
    hippocoder likes this.
  3. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,333
    If copy-and-pasted this code from somewhere, it looks like some parts of the code are missing. in the first code, there should be a variable called "size" declared somewhere. In the second code, there should be a method called "PlaceNextObstacle" somewhere.
     
  4. Deleted User

    Deleted User

    Guest

    I declared a variable for "size" but then I got an error message for x and y saying "object does not contain a definition for 'x' and no extension method 'x' accepting a first argument of 'object' could be found"
     
  5. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,558
    Show the part, where you declaring size.
     
  6. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    To add to Antypodish's request, I think it would be a good idea to just paste the whole file (assuming it is not too big) rather than trying to guess what we want to see. Also, please paste the entire error message, again, not just the small part you think we want to see. :)

    Remember to use code tags:
    Code (CSharp):
    1. bool ShouldIUseCodeTagsWhenPostingCode()
    2. {
    3.     // Yes, you should.
    4.     return true;
    5. }
     
    Antypodish likes this.
  7. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Checklist for a successful thread:
    • use topic titles that describe the problem
    • use code tags
    • post the full code that is the problem
    Also can I ask the community not to reply to any thread unless you want to actually help. Let it just fade away because it's a waste of your time, which could be spent on threads where people put some effort in (ie they're genuine cries for help).
     
    Ryiah, Suddoha and Antypodish like this.
Thread Status:
Not open for further replies.