I Need Help C#

I’m Trying To Shoot My Projectile It Doesn’t Come Back & Also Duplicates When I Click The Button!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LaserProjectile : MonoBehaviour {

    public LaserProjectile projectile;

    // Use this for initialization
    void Start () {
       
    }
   
    // Update is called once per frame
    void Update () {

        if (Input.GetMouseButtonDown(0)) {

            LaserProjectile bullet = Instantiate(projectile, transform.position, Quaternion.identity) as LaserProjectile;

            bullet.GetComponent<Rigidbody>().AddForce(transform.forward * 1000);

        }
       
    }
}

Please Help!

Assuming the object this script is located on is in Quaternion.identity world rotation, then AddForce(transform.forward * 1000); will apply the force to your new projectile directly into the screen (away from you).

If you have gravity, it would then begin to accelerate in the direction of the Physics.gravity vector, probably downwards.

This all assumes your camera is facing along the +Z vector (default Unity camera direction).

If you want to understand more, put this statement on around line 22:

Debug.Break();

This will kick the editor into pause mode when you fire the bullet, and then you can single-step the editor (far right button at center top) and look in the scene view to see what your projectile is doing. You can search for the projectile in the hierarchy, select it, then press F to focus on it in the scene view, then step along to see it move.

Helped Me Know What Was Happening But Now I Need A Script To Stop the dupilicating!

Nevermind But Thank You :slight_smile: