Ill try explaining this the best i can since english isnt my first language.
So im very new to C# and Unity… im trying to do a RTS, and for this question there are 3 important scripts… Buildings, CivBuilding(has specific civilization stuff for the buildings) and then a specific script for the main building.
i want to have the building firstly without collisions and following my mouse and after i place it, only then i will enable the collision, since i want this behavior on all the buildings i did it on the “buildings” script and i tough since CivBuilding inherits its behavior and the main building script inherits CivBuilding behavior then it would work.
but i get NullReferenceException : Object reference not set to an instance
on these lines
SphereCollider sphere;
public virtual void Start () {
Built=false;
sphere = gameObject.GetComponent<SphereCollider>();
here-> sphere.enabled=false;
}
i think its because both the gerenal building script and the civBuilding script arnt attached to any object…but since my building’s class is abstract i cant add it to any object…
btw, the script works as intended because once it gets to my main building script it recognizes the collider…but i didnt really wanted to have errors on my game…should i use throw exceptions??
sry for the long text and thanks for any answers