using System.Collections; using UnityEngine; public class testGunBullet : MonoBehaviour { public Rigidbody rb; Camera camera; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { Rigidbody rb = GetComponent(); Camera camera = FindAnyObjectByType(); Ray ray = camera.ScreenPointToRay(Input.mousePosition); // i hate this //Transform cameraTransform = Camera.main.transform; Vector3 cameraPos = camera.transform.forward; rb.AddForce(cameraPos * 500000 * Time.deltaTime); StartCoroutine(SelfDestruct()); } IEnumerator SelfDestruct() { yield return new WaitForSeconds(1f); Destroy(gameObject); } }