Search Unity

REQ for help with two scripts ...

Discussion in 'Scripting' started by DaveyJJ, Aug 22, 2005.

  1. DaveyJJ

    DaveyJJ

    Joined:
    Mar 24, 2005
    Posts:
    1,558
    Me again. :wink: Why won't this script work, anyone ... the var objects are correctly linked in the inspector from the hierarchy. :cry:

    Code (csharp):
    1.  
    2. var btnplayagain : Transform;
    3. var btnnothanks : Transform;
    4. var scnlose : Transform;
    5.  
    6. function OnMouseDown () {
    7.     /* Destroy the objects currently on the screen */
    8.     Destroy (btnplayagain);
    9.     Destroy (btnnothanks);
    10.     Destroy (scnlose);  
    11.     /* Load the level again */
    12.     Application.LoadLevel (0);  
    13. }
    14.  
    And how do I complete the following, please ... if you haven't run out of patience yet ...

    Code (csharp):
    1.  
    2. /* counts the planes as they are made to enter or leave the matching area of the airport */
    3.  
    4. var aircraftYellow : GameObject;
    5. var yellowArea : GameObject;
    6. var aircraftcountYellow = 0;
    7.  
    8. var aircraftGreen : GameObject;
    9. var greenArea : GameObject;
    10. var aircraftcountGreen = 0;
    11.  
    12. function Update () {
    13.     /* we add to the count of the aircraft type if it is inside the correct areas - detect collision with area */
    14.    
    15.    // here using onCollisionEnter for both yellow and green objects
    16.     (((( I assumed that it'd be something like ...
    17.   if onCollisionEnter aircraftYellow with yellowArea
    18.   add 1 to aircraftyellowCount .... and something similar for green
    19.  if onCollisionEnter aircraftGreen with greenArea
    20.   add 1 to aircraftgreenCount
    21.  
    22.   // the rest from here down works fine
    23.  
    aircraftYellow and aircraftGreen are prefab objects to make it easier.

    Thanks! Looking forward to 1.1 soon!
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Do you get any errors when running the first script?
    Does it print anything to the console?


    Code (csharp):
    1.  
    2. /* counts the planes as they are made to enter or leave the matching area of the airport */
    3.  
    4. var aircraftYellow : GameObject;
    5. var yellowArea : GameObject;
    6. var aircraftcountYellow = 0;
    7.  
    8. var aircraftGreen : GameObject;
    9. var greenArea : GameObject;
    10. var aircraftcountGreen = 0;
    11.  
    12. function OnTriggerEnter (other : Collider) {
    13.   if (other.gameObject == aircraftYellow) {
    14.      aircraftcountYellow++;
    15.    }
    16.  /// do same for green  aircraft
    17. }
    18.  
    19. function OnTriggerExit (other : Collider) {
    20.   if (other.gameObject == aircraftYellow) {
    21.      aircraftcountYellow--;
    22.    }
    23.  /// do same for green  aircraft
    24. }
    25.  
    26.  
    The object you attach this script to has to be a trigger.
     
  3. Richard_B

    Richard_B

    Joined:
    Jul 22, 2005
    Posts:
    436
    First script: Not sure about the load level bit, but the Destroy needs Objects as input, so if you change the "vars" to eg
    Code (csharp):
    1.  
    2. var btnplayagain : GameObject;
    3.  
    then the destroy part should work.

    Richard.