So i have a script in C# for firing bullets and moving object tagged as “Target” from one side to another. I can’t figure out how to change it so when i click, the bullets go to in my Target direction. I don’t want bullet to follow this obejct. Just fire where it was when i clicked mouse button. I’m pretty newbie in coding.
using UnityEngine;
using System.Collections;
public class Shooting : MonoBehaviour
{
public Rigidbody2D projectile;
public float speed = 20;
Transform Target;
void start() {
GameObject target_go = GameObject.FindGameObjectWithTag("Target");
}
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
Rigidbody2D instantiatedProjectile = Instantiate(projectile,transform.position,transform.rotation)as Rigidbody2D;
instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0,speed));
}
}
}