- Home /
Question by
GamesDeveloper12 · Jun 11, 2015 at 01:33 PM ·
c#javascriptgameobjectinstantiateprefab
Bullet Instantiation
I have been converting an old project from javascript to c-sharp and cannot seem to get the following to work:
In Javascript i had:
var b:Bullet = Instantiate(_bullet,_bulletPoint.transform.position, transform.rotation);
and now in c# i have:
Bullet b = Instantiate(_bullet, _bulletPoint.transform.position, transform.rotation)as Bullet;
but nothing is fired and no errors are displayed in the console. In the inspector i occasionally see it say "deleted gameobject", could that be my bullet ?
It works perfectly in javascript, but i cannot get it to work in c-sharp
Comment
Not sure about that, but try using GameObject ins$$anonymous$$d of Bullet in the beginning and the end of the line like this
GameObject b = Instantiate(_bullet, _bulletPoint.transform.position, transform.rotation) as GameObject;
Answer by zab · Jun 11, 2015 at 07:56 PM
The Bullet is some of your MonoBehauvior?
Bullet b = (Instantiate(_bullet, _bulletPoint.transform.position, transform.rotation) as GameObject).GetComponent<Bullet>();