Answer the question
In order to leave comments, you need to log in
The == operator does not evaluate to true, so my projects fly indefinitely. How to fix?
public class Bullet : MonoBehaviour
{
public float speed;
Vector3 bulletEndPos;
[SerializeField] Controller player;
void Start()
{
player = GameObject.Find("Player").GetComponent<Controller>();
bulletEndPos = transform.position + transform.forward * player.trailDistance;
}
void FixedUpdate()
{
transform.Translate(Vector3.forward * speed * Time.deltaTime);
if (transform.position == bulletEndPos)
{
Destroy(this.gameObject);
}
}
Answer the question
In order to leave comments, you need to log in
It is necessary not to compare the exact coordinates, but the distance at which the bullet flew away.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question