I have a player object carrying multiple guns. The guns each have their own fire delay, but they also pass a global fire delay to the player to limit it in firing multiple guns. The guns all derive from GunBase, which is where the relevant code is. The player is a MonoBehavior, and also implements the contract ifcGunUser.
The odd thing is the code that calls the interface method is being called, with the correct interface reference, but the interface method never gets called. (All checked with the log.) Can anyone help me learn what I am doing wrong?
The code is trimmed to what I think is relevant for readability; I’ll add more if needed.
PlayerController:
public class PlayerController : MonoBehaviour, ifcGunUser {
private float nextFire = 0;
public void GunStun(float time)
{
nextFire = Mathf.Max(nextFire, (Time.time + time));
Debug.Log(Time.time + " GunStun, nextFire = " + nextFire); //Never shows up in the log
}
}
ifcGunUser:
public interface ifcGunUser
{
void GunStun(float time);
}
GunBase:
public class GunBase : MonoBehaviour {
public ifcGunUser owner;
public Transform firePosition;
public GameObject projectile;
public float fireStun; //Time after firing before ANY weapon can be fired
public virtual void DoShot()
{
Instantiate(projectile, firePosition.position, firePosition.rotation);
Debug.Log ("GunBase, calling GunKickback: " + fireStun); //This shows up with the correct value
Debug.Log ("Interface: " + owner); //This shows up with Interface: soldier (PlayerController)
owner.GunKickback(fireStun);
}
}