I’m doing a project, where you hit the “1” key, and a projectile fires at the player’s current position. When the 1 key is pressed, the bullet will LookAt the player, and then add forward force. However, the bullet (or projectile) is a prefab. In the prefab of the bullet (under Project), I have slots of the Player Object, the Explosion, and the Projectile Type. All is working but the Player Object slot. Can you not drag GameObjects into slots that belong to Prefabs? For example, the explosion is already a prefab, so that actually let me put it into the explosion slot. The projectile is also a prefab, so that worked, too. But the player object is under the Hierarchy (though, it is a prefab), and it won’t let me drag it onto a slot that belongs under my projectile (which the projectile is a prefab under Project). If I drag the player prefab, that won’t work as the prefab doesn’t update its vectors runtime.
Also, here is the code to the script if you can help me to fix the problem above:
var playerObject : GameObject;
var explosion : Transform;
var projectileType : GameObject;
var playerVector : Vector3;
var explodeVector : Vector3;
var projectileVector : Vector3;
function OnCollisionEnter()
{
projectileType = projectileType;
projectileVector = projectileType.transform.position;
explodeVector = projectileVector;
print("X: " + explodeVector.x + " " + "Y: " + explodeVector.y + " " + "Z: " + explodeVector.z);
Destroy (gameObject);
var clonedExplosion : Transform;
clonedExplosion = Instantiate(explosion, transform.position, transform.rotation);
}
Any help is greatly appreciated.