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

Scoring System

Discussion in 'Scripting' started by jamie_con, Apr 30, 2021.

  1. jamie_con

    jamie_con

    Joined:
    Feb 26, 2021
    Posts:
    14
    Hi, I'm working on a little (American) football VR demo, and I've ran into a big problem. I was able to make the WR (a gameObject) catch the football that the player throws by having the receiver become the child of the football after a collision between the two was connected.

    However, what I haven't been able to figure out is how to make a scoring system. Basically what I want to do is have it so that when the receiver, only when it's the child of the football, enters the a certain area (the endzone), it does something like flashes particles. One suggestion that I got was to make a script to hold a collision check and the hasBall variable, but I haven't been able to figure it out. Any suggestions?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,756
    Cheap and cheerful is to make a trigger around the endzone and if the ball enters that when it is live and carried, you score. Obviously when you score you have to make sure the ball also becomes dead otherwise it would just keep scoring and scoring again and again.

    It's basically a little state machine... identify the states things can be in and when you want to detect stuff in the trigger zone. You can also look up general tutorials on state machines to see what I mean by that.
     
  3. jamie_con

    jamie_con

    Joined:
    Feb 26, 2021
    Posts:
    14
    I was thinking of doing something like this, I just couldn’t figure out how to implement it into a script
    EDIT: Actually I was looking through some tutorials like you suggested, and I think I got it now. Thanks for the suggestion!
     
    Last edited: Apr 30, 2021
    Kurt-Dekker likes this.
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,756
    You're welcome! Often the best way forward with this stuff is in "layers." Like first get the trigger in there and get it so the ball going into the trigger area AT ALL gives you a TD.

    Then add a check for the ball being live.

    Then add a check for the ball being properly possessed, etc.

    That way at each step you build confidence in what you have made so far.