*Edit,
Seems to be working now.
||||||
Hi there,
Is there a way I can reference the object which created another via instantiate? In other words… if objectX creates objectY, and there are tons of objectX’s in scene (bullet class), how can I get objectY (bullet trail) to reference THE bullet that shot it?
var newObject : MyScript = Instantiate(myPrefab, pos, rot);
newObject.creator = gameObject; //where owner is a variable in your script
thanks,
I am trying to figure it out.
what I have is a script on the bulletCreator object.
instantiate(bulletGameObject)
then in the bullet
I have a script
instantiate(bulletCloudObject).
It is running but I am having trouble matching the rotation of the bulletCloud to the bullet.
Why not just parent one of the GameObjects to the other?
so should i just put the cloud object into bullet, both on a prefab level? then when bullet calls cloud, just match parent rotation?
I’m not sure what you’re trying to do but if you just want the cloud to follow the bullet around exactly then making the cloud a child object of the bullet is the easiest way to achieve that.
The issue for me is this.
Gun, creates bullet.
Bullet creates cloudTrail.
CloundTrail is a CloudObject Instantiated, over and over as long as bullet exists.
The problem is I am getting all types of weird reactions in regards to the trail. It is scaled wrong, rotated wrong and now seemingly creating its own positions.
Not sure, will keep playing with I guess.
//this script is the manager of the cloud passsing bullet itself
///on creation of the bullet (instantiated in wpnRealmScript)...
/////a projectile is shot along a vector (handled by wpnRealmScript)
///as the bullet flies, little poofs of cloud will be released from behind it.
///these poofs are created via instantiate, invokeRepeating.
///as long as this bullet, owner exists, the clouds are created.
var cloudPoof : GameObject;
var size1 : Vector3; //size is that there are two alternating sizes
var size2 : Vector3;
var timeVar : float; // used via InvokeRepeating
function Start()
{
InvokeRepeating("createPoof", 0.01, timeVar);
}
function createPoof()
{
Instantiate(cloudPoof, transform.position, transform.rotation);
transform.localScale = Vector3(1, 1, 0.1);
}
this code is from an prefab objects script. It is attached to the bullet. This works when I just did a mini test level, but in game, at the moment, it has its issues.