Need help with bullet shooting at player

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.

You can’t put scene objects into a prefab. This is because that instance of an object won’t exist in any other project with a different scene, thus rendering that prefab link worthless.

If you want your player object to be draggable onto the prefab, create a prefab player object to drag onto it. Since you can’t do that, you should probably either send it to the bullet on creation or have the bullet find it with GameObject.FindWithTag(“Player”);.

You’ll have to tag the player object player for the above to work, of course.

Thanks, I understand where I can use GameObject.WithWithTag(“~NAMEHERE~”), however, it’s not working. You said I can “send” it? What do you mean?

Thanks for the help.

When using a game object “Find” system, it returns a gameobject - it’s the same result as a drag and drop.

let’s say your player is named player.
var projectile : GameObject; // Drag and drop from the assets.

function Update()
{
    if (Input.GetKeyDown("1"))
   fire();
}

function fire()
{
clone = Instantiate(projectile,transform.position,transform.rotation).gameObject;//CLone is the game object we instantiated.
clonescript = clone.GetComponent(BulletScript);//Replace BulletScript with the name of your script - case sensitive - no numbers as first letter - no spaces.
clonescript.playerObject=  GameObject.Find("player");//Find an object named player. If there is more than one, it will return the first. Again, case sensitive.
}