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

Need some scripting help

Discussion in 'Scripting' started by MIST0, May 2, 2014.

  1. MIST0

    MIST0

    Joined:
    Apr 26, 2014
    Posts:
    53
    Hello I am new to scripting I could do with some help.

    I am creating a game which is a modified version of the roller ball tutorial, basically I want a script that counts the cubes as they are knocked off the plane. So if they pass by a certain set of coordinates for example it counts up.

    I am just looking for some example code and functions that I can work with.

    Thanks for any help.
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    You could put a trigger below your plane and add the OnTriggerEnter function to your cube's script. Then add a tag to the trigger and check in the cubes OnTriggerEnter function, if the trigger object is tagged with that tag. If so, you can increment your counter by 1.

    Second way to do this, check on every cube whether it's y-coordinates are less than a certain value and if so, increment your counter by 1. But this needs some more control as you also need to stop it from counting, either by disabling/destroying the cubes in the same frame or by adding another boolean for the control of the counting.
     
  3. MIST0

    MIST0

    Joined:
    Apr 26, 2014
    Posts:
    53
    Thanks I will look into those two options.