Assets/Scripts/Character Classes/CharacterGenerator.cs(10,23): error CS1061: Type PlayerCharacter' does not contain a definition for Awake’ and no extension method Awake' of type PlayerCharacter’ could be found (are you missing a using directive or an assembly reference?)
and here’s my code:
public class CharacterGenerator : MonoBehaviour {
private PlayerCharacter _toon;
// Use this for initialization
void Start () {
_toon = new PlayerCharacter();
_toon.Awake();
}
// Update is called once per frame
void Update () {
}
void OnGUI() {
GUI.Label(new Rect(10, 10, 50, 25), "Name");
_toon.name = GUI.TextArea(new Rect(65, 10, 100, 25), _toon.name);
}
}
The code isn’t finished but the tutorial says that I should have no errors by now, yet I do.
using UnityEngine;
using System.Collections;
public class PlayerCharacter : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
But we were told not to put anything in it yet and once again should get no errors anyway
Oh hell… Awake is not public. you cant call it from another class. It is, however, called automatically when the object is created. Comment out the line and see if it works.
It’s probably a bad design decision to call Awake, it serves a pretty specific purpose. If this is someone else’s code just add this to your PlayerCharacter class - they must have missed it:
That helped it. The person who made the tutorial is using an older version of unity so the scripting must’ve been slightly different between then and now.
That’s sort of the case here. Awake is private in Monobehavior and isn’t defined in PlayerCharacter class. However, the author of the code isn’t calling a Monobehavior Awake method, it’s simply a method that he has called “Awake” in his own framework.
I’ve found the tutorial video…
Reading some of the youtube comments, it’s apparent that the author re-edited the video at some point and forgot to include the modifications to PlayerCharacter.cs. It’s clear from the tutorial that PlayerCharacter inherits from BaseCharacter which includes the Awake method. You can see the Awake method code at 9:49 near the end of the video…
I don’t believe Awake, Start, or Update are virtuals inherited from Monobehaviour. So the way his PlayerCharacter class was written, it’s not that it wasn’t public (although we do typically leave them private) so much as it simply wasn’t there.
when I started programming c++ I never got past errors. I would copy stuff from online or from a book and nothing ever worked. This is because A) I knew nothing about how c++ worked and B) I always had syntax errors that I never knew about because of A)
What ur trying to do is learn Unity before you understand how C# works.
Eventually, u will get it, its just a harder road.
My suggestion is to find stuff that works and tinker with it. If something with 50 lines of code works, but u want to tweak it, and one line suddenly makes the whole thing stop working. The error is pretty obvious.
Reiterating what has been said; you’re going to want to do a crash course in C#/OOP and possibly some smaller unity projects before you tackle those BurgZerg Arcade tutorials; they’re really good to follow along, but if you lack an understanding as to why he’s doing what’s he’s doing: you’re going to end up with tons of errors that you can’t fix; he tends to revisit errors several lessons into the future, or ignore them entirely/fix them off cam. Just my 2 cents. Good luck.