instantiating problems

sometimes C# makes me want to stab my head.

anyways, why can’t I do this:

GameObject shot;
shot = Instantiate (IcarusBullet, transform.position + transform.forward * collider.bounds.extents.z, transform.rotation);

It bitches Cannot implicitly convert from UnityEngine.Object to GameObject.

okay, so I force the cast:
GameObject shot;
shot = (GameObject)Instantiate (IcarusBullet, transform.position + transform.forward * collider.bounds.extents.z, transform.rotation);

but then I get InvalidCastExceptions (cannot cast from source type to destination).

Ultimately I just want to call:

shot.setColor(getColor());

after instantiating my bullet so its the right color

(setColor and getColor are defined in IcarusBaseObject which IcarusBulletScript inherits from)

Oh what type is Icarus Bullet (declared as in the code)? It sounds like IcarudBullet isn’t a GameObject, but just an Object.

This code of mine works fine:

...
public GameObject sparks;
...
...
GameObject newSparks = (GameObject)Instantiate( sparks, collision.contacts[0].point, gameObject.transform.rotation );

huzzah, I see what I was doing wrong. HUGS thank you!

And just for your knowledge of my current hierarchy

Object

  • Component
    – MonoBehaviour
    — IcarusBaseObject
    ---- IcarusBulletScript
    ---- IcarusController
    ----AIBase
    -----ShimmayAI