I need some help setting up an abstract class. Im confused about class variables and how they inherit, if they even do. Spawntime is being treated as a variable shared by all subclasses. Also, is it possible for the child classes to extend on the abstract classes Update() method? Here is the Abstract Class code I have now:
public abstract class AbstractProjectile : MonoBehaviour {
public bool DestroyOnTimer = false;
public bool DestroyWhenInvisible = true;
public float TimeToLiveInSeconds = 1.0f;
//Time the Projectile was created
private float spawnTime;
// Use this for initialization
void Start ()
{
spawnTime = Time.time;
}
// Update is called once per frame
void Update ()
{
//Destroy the projectile if its timer is over
if (DestroyOnTimer) {
if ((Time.time - spawnTime) > TimeToLiveInSeconds)
{
Destroy(gameObject);
}
}
//Call Child projectiles move method
move();
}
public virtual void move() { }
}
Here is the Child Code:
using UnityEngine;
using System.Collections;
public class SinBulletScript : AbstractProjectile {
public float speed = 1000.0f;
public float Amplitude = 600.0f;
public float Omega = 15.0f;
// Use this for initialization
void Start ()
{
Vector3 shipPosition = GameObject.Find("Ship").transform.position;
shipPosition.y += 100;
transform.position = shipPosition;
}
void move()
{
gameObject.rigidbody.velocity = new Vector3(Amplitude * Mathf.Sin(Time.time * Omega), speed, 0);
}
}