I’m making a multiplayer spaceship game, like Artemis or Star Trek Bridge Crew, where different players control different parts of one ship. So I have it that when each player is created, the server then calls a function on the player called RpcRegisterShip, which takes the ship they are assigned to as a parameter. This ship is then used to get the ship’s transform, the ship’s rigidbody, or whatever else the player will need to interact with on the ship.
It works just fine when I have each type of player, (pilot, gunner, engineer, etc.), have their own RpcRegisterShip function, but I’m trying to be a good programmer and implement inheritance. So I made a base class, “PlayerControls,” and then I have “PilotControls,” “GunnerControls,” etc., inherit from that class.
The base RpcRegisterShip gets some basic info, but each of the child classes override RpcRegisterShip so they can each get what special information they need. The overriding RpcRegisterShip still calls the base RpcRegisterShip though.
What’s weird is that the overriding RpcRegisterShip does not seem to be calling the base function. It might even be calling itself. What am I doing wrong?
Base Class:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
abstract public class PlayerControls : NetworkBehaviour {
protected GameObject ship;
protected Transform shipTransform;
[ClientRpc]
public virtual void RpcRegisterShip (GameObject receivedShip) {
Debug.Log("Register Ship Base");
if(!isLocalPlayer) {
return;
}
ship = receivedShip;
shipTransform = ship.GetComponent<Transform>();
}
...
}
Pertinent part of the derived class:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class PilotControls : PlayerControls {
...
private Rigidbody shipRigidbody;
[ClientRpc]
public override void RpcRegisterShip (GameObject receivedShip) {
if(!isLocalPlayer) {
return;
}
Debug.Log("Register Ship Derived");
base.RpcRegisterShip(receivedShip);
shipRigidbody = receivedShip.GetComponent<Rigidbody>();
}
...
}