Search Unity

character building error 2

Discussion in 'Documentation' started by Thecruzer, Oct 28, 2017.

  1. Thecruzer

    Thecruzer

    Joined:
    Aug 20, 2017
    Posts:
    18
    I'm still new at C# and I've taken this code from a tutorial when they were in unity 4. I rewrote the code like they had it for the line that the error is being produced and I'm still getting the same error. In character building error I was trying some things and forgot to delete out the semicolons but that still didn't fix the problem. I've attached the code and the error again. I'm hoping for a more comprehensive answer.

    Also does the public int for strength agility etc. need to be capitalized like Strength Agility etc.?

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class BaseCharacterClass
    {
    private string characterClassName;
    private string characterClassDescription;
    //Stats
    private int strength;
    private int agility;
    private int wisdom;
    private int intellegence;
    private int charisma;
    private int commonSence;
    private int wit;
    private int charm;
    private int shrewd;
    private int dexterity;
    private int stamina;
    }
    public string CharacterClassName{
    get { return characterClassName; }
    set { characterClassName == value; }
    }
    public string CharacterClassDescription{ get; set; }
    public int Strength { get; set; }

    public int Agility { get; set; }

    Assets/Scripts/BaseCharacterClass/BaseCharacterClass.cs(22,11): error CS1525: Unexpected symbol `string', expecting `class', `delegate', `enum', `interface', `partial', or `struct'
     
  2. CubicCBridger

    CubicCBridger

    Joined:
    Apr 19, 2017
    Posts:
    44
    You are declaring the properties, CharacterClassName CharacterClassDescription, Strength and Agility outside of the class BaseCharacterClass. Currently BaseCharacterClass has a bunch of private fields and nothing else, as you have a curly bracket after the stamina field. Another mistake i'm assuming is that a only your CharacterClassName property is attempting to use its corresponding private field, where as the other properties are not.

    P.S You probably shouldn't be posting a new thread for every change you make
    P.P.S I'm also guyessing that documentation is probably the incorrect category to post these threads in.