So about a week ago I made a shooting script for my third person shooter,
using UnityEngine;
using System.Collections;
public class ShootingScript : MonoBehaviour {
public Transform bulletSpawn;
RaycastHit hit;
public float range;
public Rigidbody bullet;
public float force;
public Transform raycastStart;
Vector3 foundHit;
// Update is called once per frame
void Update () {
bulletSpawn.LookAt(foundHit);
Raycast();
if(Input.GetMouseButtonDown(1))
{
Shoot();
}
}
void Shoot()
{
Rigidbody clone;
clone = Instantiate(bullet, bulletSpawn.transform.position, bulletSpawn.transform.rotation) as Rigidbody;
clone.velocity = bulletSpawn.transform.TransformDirection(Vector3.forward * force);
}
void Raycast()
{
if(Physics.Raycast(raycastStart.transform.position,raycastStart.transform.forward, out hit, range))
{
foundHit = hit.point;
}
}
}
and when I played my game today, the bullet wasn’t spawning. Bullet Spawn is still looking at the foundhit point, but when i hit left mouse, no bullet comes out. So I know that the problem is in the Shoot() void, but I can’t find anything wrong. There is nothing in the console comin up about this and all variables are assigned. Can anyone help me?