Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Collide Jumpscare

Discussion in 'Scripting' started by Corrothon, Aug 17, 2020.

  1. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    edit: nvm
     
    Last edited: Aug 23, 2020
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,606
    Ok. Where is your problem?
     
    PraetorBlue likes this.
  3. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    The problem is that I don't know how to do it :/ Because I want to have it collide with the player and then jumpscare them with an image.
     
  4. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,606
    Define in your game what 'jumpscaring' means for you. Could be an image flashing, the creature being teleported to your face and so on. Then create a function that does just that once you call it. Use the OnCollisionEnter of the creature, check if it collided with the player, if so call the previously defined function to do what you want.
     
    PraetorBlue likes this.
  5. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    I want it to flash an image and have a sound
     
  6. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,606
    Great. Create a function doing just that. Break the problem into pieces. Do you know how to play a sound? If so, good, implement it. If not, that should be a quick google search. Do you know how to flash an image? Same as above. After you can do both, create one function to do both. There are several approaches.
    Once you have one function for starting / playing the desired effect, simply call it on collision.
     
    Vryken likes this.
  7. mgrekt

    mgrekt

    Joined:
    Jun 22, 2019
    Posts:
    92
    Key tip for this ontriggerenter or ontriggerstay depending on your use.