How can this give me a null reference problem:
function Update () {
var AC : AttackComponent = GetComponent(AttackComponent);
AC.findNearEnemy();
}
The AttackComponent script is already put on my gameobject which is called “smallUnit”:
Moderator Note: Remember that you can also edit your questions when you need to give more details. I thought the pictures would stay on the server after I deleted the answer. They didn't. -Jamora
EDIT:
First of all…I am so amazed of this community, wow thanks for the replies!
Back to topic:
My gameobject has 3 important scripts on it:
- AttackComponent(instantiated as AC)
- MoveComponent(instantiated as MC)
- UnitController(instantiated as UC).
The last stated is the “main” script of the gameobject which works as a bridge between the two first stated, so they can call different functions through the UnitController.
Anyway as you can see, the three scripts is attatched to the gameobject:
Broken down to this scenario, my UnitController has this:
var AC :AttackComponent;
var MC :MoveComponent;
function Awake(){
AC = GetComponent(AttackComponent);
MC = GetComponent(MoveComponent);
}
function Update () {
AC.findNearEnemy();
}
My AttackComponent has (broken down for this scenario) this:
var UC : UnitController;
function Awake(){
UC = GetComponent(UnitController);
}
function findNearEnemy(){
//nothing yet, just a dummy function
}
I think it is a problem with the AC.findNearEnemy(). My MC in UnitController doesn’t give me any problems, so I am on unknown ground for my sake
The error message i get: