Combining These Scripts

Ok so i have a look at mouse position script, and a shoot script. i want to make it so it spawns the bullet, and shoots it towards the mouse position. How would i do that?

Look At Mouse

var playerPlane = new Plane(Vector3.up, transform.position);
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hitdist = 0.0;
if (playerPlane.Raycast (ray, hitdist)) {
var targetPoint = ray.GetPoint(hitdist);
var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Lookspeed * Time.deltaTime);
}

Shoot Script

	function Shoot(){
var bullit = Instantiate(PistolbullitPrefab ,transform.Find("spawnPoint").transform.position, transform.rotation);	
	bullit.rigidbody.AddForce(transform.forward * 9000);

}

bumpity bump

Well, unless I misunderstand what you are trying to do, you could just paste the Shoot function into the other script and call it from inside the “if” statement:-

if (playerPlane.Raycast (ray, hitdist)) {
   ...
  transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Lookspeed * Time.deltaTime);
  Shoot();
}

You will also need to add the PistolbullitPrefab variable in the script and link it up, of course :wink: