I’m getting a console error when I try to override a virtual member in an inherited class.
Error: Same name multiple times included:::Base(MonoBehaviour) stageObjectType
StageObject.cs
using UnityEngine;
using System.Collections;
public enum StageObjectType {Player = 0, Ally = 1, EnemyAI = 2, Character = 3, Collectable = 4, Obstacle = 5, Building = 6 }
public class StageObject : MonoBehaviour {
public virtual StageObjectType stageObjectType;
}
Character.cs
using UnityEngine;
using System.Collections;
public class Character : StageObject {
public override StageObjectType stageObjectType = StageObjectType.Character;
}
Thanks for your reply. My example may not have been well chosen. I was curious as to how to use a virtual / override and I’m still hoping to get some guidance.
Using this example without virtual/override, and attempting to assign a new value to the inherited public member actually causes a console parsing error. I can however assign the member a new value as long as I create a constructor function for the subclass and assign the new value there.
virtual and override is for functions, not fields.
its a mono 1.2.5 bug that you can even do it, such mess like the one there will lead to compiler errors if you put the code into a non-bugged .net environment (VC#, mono 2.x and unity 3)