Attach a trigger to a script

It would be nice if someone helped me with this. When a player goes though the trigger (myTrigger) it should shoot a prefab named “Bullet” and that works when there is no trigger function (A similar script is attached to the player but it has a update function and GetMouseButtonDown statement, that works like a charm). But now I want a turret to shoot when the player goes through the trigger.
I’m good at scripting but I don’t know how to put this in code. Thank you :slight_smile:

#pragma strict

var Bullet : Rigidbody;
var Speed = 20;
var myTrigger : ???;

function OnTriggerEnter (myTrigger) {
	if (GameObject.FindWithTag("Player"))
	{
		var clone = Instantiate(Bullet, transform.position, transform.rotation);
		clone.velocity = transform.TransformDirection(Vector3(0, 0, Speed));
		
		Destroy (clone.gameObject, 3);
	}
}

Are you having issues figuring out how to get scripts on the objects to speak with one another? You’re going to want to use something like SendMessage or GetComponent to access the turret gameObject when the function to shoot the turret. BTW The way you’re doing the existing script is not really idea. Non player objects can currently trigger this and it will shoot. You want something like

if (myTrigger.gameObject.tag == player).

IMO in collisions and triggers you already have the object doing the bumping. Best to use that reference IMO.