Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

projectile script not working

Discussion in 'Getting Started' started by volcanicfire33, Jan 28, 2020.

  1. volcanicfire33

    volcanicfire33

    Joined:
    Jan 28, 2020
    Posts:
    9
    hello whoever is reading this,
    i need some help.
    i'm trying to make my players bullets disappear when they reach the cursor.
    i wrote this:


    void Update(){
    if(transform.position == targets){
    Destroy(gameObject);
    }
    }
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    2,959
    Hello! Firstly, let me point you towards the guide for using script tags. It helps make your code easier to read for people helping you.

    The code you've provided isn't very obvious as to how it works in the grand scheme of things. Could you explain a bit more about what objects this script is attached to? What is the targets variable in this case?
     
    Bill_Martini likes this.
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    8,953
    Comparing vector3's exactly to each other is not a great idea. You will probably want to check if they are within a certain range, but it is hard to tell what would work best without knowing much about your game.
     
unityunity