I have this abstract class that inherits from MonoBehavior. In its Start method, it calls on of the classes abstract methods, SetProbability(). For some reason, this causes Unity to crash.
I don’t know much about abstract classes, and even less about how MonoBehavior’s methods tie into this. Can someone please take a look at this to see what I’m doing wrong? Can an abstract class’s Start() call a abstract method so that each derived class has that method called for it on Start?
using UnityEngine;
using System.Collections;
public abstract class CardInformation : MonoBehaviour {
protected float Width { // width in world units
get{
return Width;
}
private set{
Width = value;
}
}
protected float Height { // height in world units
get{
return Height;
}
private set{
Height = value;
}
}
[Range(1,50)] protected int Probability; // 50 is 100% of the deck
// Use this for initialization
void Start () {
Width = (606f/1024f) * transform.localScale.x;
Height = (1024f/1024f) * transform.localScale.y;
SetProbability();
}
public bool Inside(Vector3 pos){ // Returns true if the pos is inside this card
bool retBool = false;
if (pos.x <= transform.position.x - Width/2 && pos.x >= transform.position.x - Width/2
&& pos.y <= transform.position.y - Height/2 && pos.y >= transform.position.y - Height/2) {
retBool = true;
}
return retBool;
}
public int GetProbability(){
return Probability;
}
abstract public void Action(GameObject targetTile, GameObject[] tiles); // This function will be overriden by each card for its specific action
abstract public void SetProbability();
}
Derived class
using UnityEngine;
using System.Collections;
public class PlusOne : CardInformation { // Inherits from the CardInformation, must over ride Action
override public void Action(GameObject targetTile, GameObject[] tiles){
targetTile.GetComponent<TileInformation>().Strength += 1;
}
override public void SetProbability(){
Probability = 50;
}
}