determine if 2 objects are the same type

i thought i could do this with


but it doesnt seem to work

i’m doing this for an inheritance issue.

Weapons have projectiles

Ballistic weapons however need to have ballistic projectiles

when you assign a projectile to a ballistic weapon it does a if (projectile type == ballistic projectile) then do stuff to actually assign it.

heres my code

public override Projectile projectile {
	get {
		return _BallisticProjectile;
	set {
			_BallisticProjectile = value as BallisticProjectile;
			base.projectile = _BallisticProjectile;

when i take a torpedo which inherits from ballistic projectile and assign it it says the result is false. (i confirmed with a debug.log)

is there a way to debug.log the type of something as well?
I’m sure there is a simple method of comparing and accessing types but i don’t know what it is.

You can check for type equality with the “is” keyword, see this page on MSDN:

The is keyword tests type compatibility, i.e. if the comparison returns true it means the first object can be statically cast to the other without raising an exception.

This is what you want here, because you need to ask whether an object is of type ballistic projectile, or if it is of a type that derives from ballistic projectile.

you can use .GetType() method of the class or typeof operator to get the type and then use .ToString() to get the name of the type as string.