How DO You Make An Object Shoot A Projectile In Unity So That The Projectile Goes Straight And Only Last A Certain Amount Of Time Before It Disappears. Also What Object Would I Put This Script In.
To create the projectile, you use the Instantiate function to make a copy of a GamneObject (commonly a Prefab).
To make it face the right direction, you set it’s transform.rotation to the rotation of the object that “shoots” it. This can be passed directly as a parameter of the Instantiate function.
To Destroy it after a certain amount of time, you use the Destroy() function:
Destroy(yourProjectileGameObject, lifetimeInSeconds);
To make it move, you have multiple options depending on your game. You can use AddForce with a RigidBody, or Transform.Translate, or Transform.MoveTowards, or Vector3.Lerp…
The script can be on the object that shoots the projectile, or the character that uses it. Theoretically, it can be anywhere as long as you have the required variables available (the script needs to know where to instantiate, for example).