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. Dismiss Notice

Hello i have error CS1061 and CS0246, please help.

Discussion in '2D' started by Gibonen, Oct 10, 2020.

  1. Gibonen

    Gibonen

    Joined:
    Oct 4, 2020
    Posts:
    6
    Hi I am trying to make enemy AI script and i am getting these two errors idk why.
    I have game object named as Player in my scene and it is defined in script so how i can solve that out, please help ;p
    upload_2020-10-10_21-15-1.png
    upload_2020-10-10_21-15-45.png
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Code (CSharp):
    1. public void Die() {
    2.    //"GameObject", should be "gameObject". Capitalization matters.
    3.    Destroy(this.GameObject);
    4.  
    5.    //The type "player" doesn't exist. Do you have a script called "Player", perhaps? Again, capitalization matters.
    6.    player.GetComponent<player>().points += pointsToGive;
    7. }
     
  3. Gibonen

    Gibonen

    Joined:
    Oct 4, 2020
    Posts:
    6
    ok i changed that capitalization, and i dont have any script or nothing else called player.
    Capture.PNG Capture1.PNG
     
  4. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    You didn't need to change "GameObject" on line 12, that one was correct.
    "GameObject" is the type; "gameObject" is the name of the variable.
    When you're declaring a variable, you specify the type. When you're referencing the variable, you use its name.

    If you don't have a script called "Player" or something similar, then I'm not sure what component you're trying to get here:
    Code (CSharp):
    1. player.GetComponent<player>().points += pointsToGive;
    What other script do you have that has a "points" field? That would be the one you want to use between the
    <>
    symbols.
     
  5. Gibonen

    Gibonen

    Joined:
    Oct 4, 2020
    Posts:
    6
    Ok i have solution: in unity inspector i didnt have player on "Tag" player, so script could not find player.
    thank you for help ;P