Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Nov 26, 2014 at 06:50 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by RicardoAntezana · Nov 26, 2014 at 12:55 PM · colliderontriggerenterbooleanontriggerexitfunction update

Slenderman like game pages not working!

What I want is to be able to pick up pages like in Slender. Here is my script: (By the way this is a modified version of Ryandomes script)

 var Paper : int = 0;
 var paperToWin : int = 30;        
 var AllowPickup : boolean;
 
 function OnTriggerEnter (other.Collider)
     {
         if (other.gameObject.tag == "Paper")
         {
             AllowPickup == true;
         }
     }
     
 function OnTriggerExit (other.Collider)
     {
         if (other.gameObject.tag == "Paper")
         {
             AllowPickup == false;
         }
     
 function(Update)
       {
             if(AllowPickup == true)
             {
                 if(GetKeyDown("e"))
                 {
                     if (other.gameObject.tag == "Paper")
                     {
                              Paper += 1;
                              Debug.Log("A paper was picked up. Total papers = " + Paper);
                              Destroy(other.gameObject);
                          }
                  }
              }
           }
      
 function(OnGUI)
     {
          if (Paper < paperToWin)
          {
              GUI.Box(Rect((Screen.width/2)-100, 10, 200, 35), "" + Paper + " Papers");
          }
          else
          {
              GUI.Box(Rect((Screen.width/2)-100, 10, 200, 35), "All Papers Collected!");
          }
     }

I get These error messages:

 Assets/ObjectCounter.js(5,31): BCE0043: Unexpected token: ..
 
 Assets/ObjectCounter.js(13,30): BCE0043: Unexpected token: ..
 
 Assets/ObjectCounter.js(34,10): UCE0001: ';' expected. Insert a semicolon at the end.
 
 Assets/ObjectCounter.js(46,10): UCE0001: ';' expected. Insert a semicolon at the end.
 
 Assets/ObjectCounter.js(47,1): BCE0044: expecting }, found ''.



Please help!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by Caiovvs · Nov 26, 2014 at 02:12 PM

You should be doing this

 function OnTriggerEnter (other : Collider)

Because you have to treat "other" like a variable of type Collider. Also you forgot the closing brackets in the 'OnTriggerExit' function.

There are other incorrect things so I tried fixing your script, just see if this works for you:

 var Paper : int = 0;
  var paperToWin : int = 30;        
  var AllowPickup : boolean;
  var paperObject : GameObject;
  
  function OnTriggerEnter (other : Collider)
      {
          if (other.gameObject.tag == "Paper")
          {
              paperObject = other.gameObject;
              AllowPickup = true;
              
          }
      }
      
  function OnTriggerExit (other : Collider)
      {
          if (other.gameObject.tag == "Paper")
          {
              AllowPickup = false;
          }
          }
      
  function Update()
        {
              if(AllowPickup == true)
              {
                  if(Input.GetKeyDown(KeyCode.E))
                  {
                      if (paperObject.tag == "Paper")
                      {
                               Paper += 1;
                               Debug.Log("A paper was picked up. Total papers = " + Paper);
                               Destroy(paperObject);
                           }
                   }
               }
            }
       
  function OnGUI()
      {
           if (Paper < paperToWin)
           {
               GUI.Box(Rect((Screen.width/2)-100, 10, 200, 35), "" + Paper + " Papers");
           }
           else
           {
               GUI.Box(Rect((Screen.width/2)-100, 10, 200, 35), "All Papers Collected!");
           }
      }
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RicardoAntezana · Nov 26, 2014 at 04:30 PM 0
Share

Thanks so much! Its almost working now, but as soon as I pick up a paper the GUI disappears! Please help!

avatar image Caiovvs · Nov 26, 2014 at 04:46 PM 0
Share

I think you should be handling the number of papers left and other GUI in another script, maybe attached to the player or a manager game object. What is happening is that when you pick up the paper, it is destroyed, and the script(which also handles the GUI) stops working. Edit: Scratch that, just realized you attached it to the player probably.

avatar image RicardoAntezana · Nov 26, 2014 at 05:22 PM 0
Share

So any ideas? Just making sure you know I am a new to coding.

avatar image Caiovvs · Nov 26, 2014 at 05:28 PM 0
Share

I tested it and it worked fine. I added a cube with a trigger box collider and the 'Paper' tag, and a fps controller with your script. Then I walked over to the cube, pressed 'E' and it disappeared, but it still showed the number of papers at the top. What GUI are you refering to?

avatar image RicardoAntezana · Nov 26, 2014 at 06:36 PM 0
Share

Ahhh I fixed it, I by mistake checked "Allow Pickup" Sorry about this. Thanks for everything!

avatar image
0

Answer by Wisearn · Nov 26, 2014 at 02:08 PM

You need a closing bracket for

 function OnTriggerExit (other.Collider)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

OnTriggerEnter works, OnTriggerExit doesn't 3 Answers

Compound Triggers with no intermediary exit calls 1 Answer

How can I get my script to recognise when a collider exits while the box collider of the trigger object is disabled? 1 Answer

NavMeshAgent and OnTriggerEnter/OnTriggerExit 0 Answers

Make object react to certain triggers only 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges