Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to check if player has collided with gameobject.

Discussion in 'Scripting' started by Corrothon, Sep 3, 2021.

  1. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    Hello, I've been trying to do this thing for a jam but I don't know how to fix this.
    How do I make it so if the player has collided with a GameObject called PlatformTriggered then play this camera animation. The script in camera, since the animation is a camera animation.
    Yeah, it's probably simple but I can't think straight right now and I only have 2 days left for a game jam, so if you could help, that'd be great.
    Thanks.
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,510
    Just because your script is going to update the camera doesn't mean it has to be attached to the camera!

    I'd create a script that's attached to the player object, and in its OnCollisionEnter method, get the GameObject associated with the object collided with. If it's the object you want, play the camera animation, either using Camera.main or via a reference that you've assigned in the Inspector.

    Good luck with the jam! Make sure you get some rest!
     
    PedroSN0W and Corrothon like this.
  3. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    Thanks for the help! I am a little confused on how to implement it using a reference.
     
  4. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    have you used Unity before? do you know about the dragndrop behavior with the game objects and the inspector fields?
     
    Schneider21 likes this.