First, I would like to say I apologize if this has already been asked and there is already an available thread covering this. I did my very best to try and find a resolution to this using preexisting resources, but nothing is really helping me.
Next the information I've been working from is here:
It states that the virtual keyword is used to override functions/methods down the line if inherited from another object. More so it is my understanding that Unity automatically uses virtual key word unless otherwise specified.
So hypothetically with this train of thought in mind I would simply just pre-pend override in my function declaration and it should override it. However. That is not the case.
What occurs next is an error:
Assets/Scripts/Classes/Actors/TestPlayer.js(500,18): BCE0089: Type 'TestActor' already has a definition for 'getMovementVector()'.
Below are the class definitions shortened to just the initial skeleton and the functions I'm discussing.
class Actor extends DefaultGameObject {
function getMovementVector() : Vector3 {
var moveDirection = Vector3(0, 0, 0);
if(isJumping && !jumpUsed) {
//TODO: If double jump is added modify this line
//so that the speed can be changed if you want that
moveDirection.y += jumpSpeed;
if(jumpTimer < jumpTimerMax) {
jumpTimer++;
}
else {
isJumping = false;
jumpUsed = true;
//animatedImage.animateOnceAndStopAtEnd(39, 39, 41);
}
}
if((movingLeft || movingRight) && !(movingLeft && movingRight)) {
if(movingLeft) {
moveDirection.x -= moveSpeed;
}
if(movingRight) {
moveDirection.x += moveSpeed;
}
}
//applies gravity
if(!isJumping) {
moveDirection.y -= fallSpeed;
}
return moveDirection;
}
}
Below is the code for the class that inherits from the above class with its function/method.
class TestActor extends Actor {
override function getMovementVector() : Vector3 {
var moveDirection = Vector3(0, 0, 0);
if(isJumping && !jumpUsed) {
if(doubleJumpUsed) {
moveDirection.y += jumpSpeed;
}
else {
//Debug.Log("omg jumping");
moveDirection.y += jumpSpeed;
}
if(jumpTimer < jumpTimerMax) {
jumpTimer++;
}
else {
isJumping = false;
jumpUsed = true;
animatedImage.animateOnceAndStopAtEnd(39, 39, 41);
}
}
if((movingLeft || movingRight) && !(movingLeft && movingRight)) {
if(movingLeft) {
moveDirection.x -= moveSpeed;
}
if(movingRight) {
moveDirection.x += moveSpeed;
}
}
//applies gravity
if(!isJumping) {
moveDirection.y -= fallSpeed;
}
return moveDirection;
}
}
To me it seems relatively straightforward, but no matter what I do I cannot for the life of me get it to stop complaining about a method that has already been declared for it. I've tried explicitly using the virtual keyword as well. I tried adding access modifiers and that didn't change anything.
I would really appreciate any help or directions on where I can go for this. Thank you.
class Actor extends DefaultGameObject {
That's JavaScript? – jhocking Jan 2 at 1:51