I use this code :
private Projectile clone;
void Update()
{
clone = Instantiate(arrowParticle, arrowFirePos.position, transform.rotation) as Projectile;
}
The object is instantiated correctly but clone stays null I can’t figure out why?
I use this code :
private Projectile clone;
void Update()
{
clone = Instantiate(arrowParticle, arrowFirePos.position, transform.rotation) as Projectile;
}
The object is instantiated correctly but clone stays null I can’t figure out why?
Or directly reference your prefab as one of it’s components ( rigidbody example in the docs ).
Your problem here is that you are referencing your prefab as one type (Transform), and trying to reference it when instantiating as another (Projectile).
One correct example, keeping references to every instantiated projectile in a List ( requires using System.Collections.Generic ) :
public Projectile projectilePrefab;
private List < Projectile > instantiatedProjectiles = new List < Projectile > ();
void Update ()
{
Projectile newProjectile = Instantiate(projectilePrefab, arrowFirePos.position, transform.rotation) as Projectile;
instantiatedProjectiles.Add ( newProjectile );
}
is Projectile is GameObject or a prefab if its a prefab Make private to public gameObject and attache the prefab to the Projectile Object. Add the arrowParticle too for transform position.
Instantiate a Projectile with force
In both is a working instantiation for a projectile…it should help you.
What does the console print?