Small Inheriting Problem

I’ve never really done anything with Inheriting so I’m expecting the fix to this problem to be really clear to everyone else but I basically made a projectile base class to handle all the projectile movement for bullets and lasers and so on.

This is what I’ve got in the projectile base class:

using UnityEngine;
using System.Collections;

public class Projectile : MonoBehaviour {

	public float projectileSpeed;
	public float damageAmount;
		
	// Update is called once per frame
	protected virtual void FixedUpdate () 
	{
		ProjectileMovement();
	}

	protected virtual void ProjectileMovement()
	{
		transform.position = transform.position + Vector3.up * projectileSpeed * Time.deltaTime;
	}

	void OnTriggerEnter2D(Collider2D other)
	{
		if(other.tag == "Enemy")
		{
			Destroy(gameObject);
		}
	}
}

I then created a class called PlayerBullet and had it inherit projectile:

using UnityEngine;
using System.Collections;

public class PlayerBullet : Projectile {

	protected float moveSpeed;
	protected float damage;
	
	// Use this for initialization
	void Update () {
		this.projectileSpeed = moveSpeed;
		this.damageAmount = damage;
	}

}

I’m basically trying to make it so I can input separate projectile speeds and damage amounts for different projectiles so I created separate variables within the playerbullet class so I could assign them in the inspector and then have the projectileSpeed and damageAmount variables within the base class equal the same as the related variables within the playerbullet class. So as you see: “projectileSpeed = moveSpeed” is within the playerbullet class as I thought that would assign the moveSpeed varaible to the projectileSpeed variable within the base class but no matter what I do, the projectile speed within the projectile base class will always be zero and I’m not sure why.

As I said I’m new to this so I’m sorry for the most likely nooby question and I hope what I said makes sense XD

Can anyone help me?

You need to initialize your moveSpeed and damage variables in your PlayerBullet class.

using UnityEngine;
 using System.Collections;
 
 public class PlayerBullet : Projectile {
 
    //Change these values to what you want
     protected float moveSpeed = 5f;
     protected float damage = 10f;
     
     // Use this for initialization
     void Update () {
         this.projectileSpeed = moveSpeed;
         this.damageAmount = damage;
     }
 
 }

However, it would also be much simpler to just do this:

using UnityEngine;
 using System.Collections;
 
 public class PlayerBullet : Projectile {

     // Use this for initialization
     void Start() {
       //Change these to what you want
         this.projectileSpeed = 5f;
         this.damageAmount = 10f;
     }
 
 }