I have script where instance of class created. This class call function from different class. Well here is code:
Script A:
var antWorker:AntWorker;
function Start(){
antWorker = new AntWorker(gameObject);
}
function Update() {
antWorker.patrolMove(movePoints*);*
}
class AntWorker:
class AntWorker{
var currentObject:GameObject;
var patrolSpeed:int = 20;
var gravity:int = 20;
var botAction:botActions;
*public function AntWorker(currentObject:GameObject){ *
this.currentObject = currentObject;
botAction = new botActions();
}
- function patrolMove(target:Vector3){*
-
botAction.simMove(currentObject,target,patrolSpeed,gravity);* - }*
}
Class botActions:
class botActions{
function simMove(currentObject:GameObject,mytarget:Vector3,speed:int,gravity:int){
-
var currentSpeed:int = speed;*
-
var currentGravity:int = gravity;*
-
var currentPos = currentObject.transform.position;*
-
var currentRot = currentObject.transform.rotation;*
-
var controller : CharacterController = currentObject.GetComponent(CharacterController);*
-
if (controller.isGrounded) {*
-
moveDirection = mytarget-currentPos;* -
moveDirection.y = 0; // ignore vertical distance before normalization*
_ moveDirection = moveDirection.normalized * currentSpeed;_
- }*
_ moveDirection.y -= currentGravity * Time.deltaTime;_
_ controller.Move(moveDirection * Time.deltaTime);_
- currentObject.transform.rotation = getTerrainRot(mytarget,currentPos,currentRot);*
}
}
But, if I call function of botActions in Script A not through class AntWorkerm, everything works fine.I suspect that something wrong with constructor (( but can’t find where.
Exception:
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args)
antWorker1.Update () (at Assets/gScripts/classes/Animal/Insect/antWorker1.js:53)
Thanks