|
Post by britannis on Mar 28, 2016 3:54:39 GMT
In my variable declarations: // The parent transform of all projectiles. [SerializeField] Transform projectileParent; public Transform ProjectileParent { get { return projectileParent; } } This is my shoot function, where I attempt to set the projectile parent: /// <summary> /// Shoot a projectile. /// </summary> public void Shoot() { if (Time.time > nextShotTime) { // Add time. nextShotTime = Time.time + msBetweenShots / 1000;
// Fire projectile. ProjectileModel newProjectile = Instantiate(projectile, muzzle.position, muzzle.rotation) as ProjectileModel; newProjectile.transform.parent = projectileParent; newProjectile.SetSpeed(muzzleVelocity); } } What happens is projectiles are instantiated but never set to parent the transform:
|
|
|
Post by Admin on Mar 28, 2016 12:22:21 GMT
The code looks okay to me. My guess is that you forgot to assign the reference of projectile parent in the inspector? If that is the case then the field would be holding "null" and you would just be telling the instantiated bullets to not have a parent.
|
|
|
Post by britannis on Mar 28, 2016 18:42:31 GMT
Ah, I figured it out. Basically I was instantiating a projectileParent gameobject if it didn't exist, but I forgot to actually set that gameObject as the projectileParent >.>
Simple mistakes!
|
|