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 /
avatar image
-1
Question by Chibli · Jun 24, 2014 at 05:59 PM · slender

What's grong with this script?

 #pragma strict
 @script RequireComponent ( AudioSource )
 var papers : int = 0;
 var papersToWin = 5;
 var distanceToPaper : float = 2.5;
 public var paperPickup : AudioClip;  
   
 function Start () 
 {
     Screen.lockCursor = true;
 }
 
 function Update () 
 {
     if(Input.GetMouseButtonDown (0) || Input.GetKeyDown (KeyCode.E))
     {
     var ray = Camera.main.ScreenPointToRay(Vector3(Screen.width * 0.5, Screen.height * 0.5, 0.0));
     var hit : RaycastHit;
     
     if(Physics.Raycast(ray, hit, distanceToPaper))
     {
     if(hit.collider.gameObject.name == "Paper")
     {
      papers += 1;
      audio.PlayClipAtPoint(paperPickup, transform.position);
      Destroy(hit.collider.gameObject);
     }
     }
     }
 }
 
 function OnGUI ()
 {
     if(papers < papersToWin)
     {
     GUI.Box(Rect((Screen.width * 0.5) -60, 10, 120, 25),  " " + papers.ToString() + " papers");
     }
     else
     GUI.Box(Rect((Screen.width/2) - 100, 10, 200, 35), "All Papers Collected!");
 }

I dont know how to script, i am a designer, but my question is why when i picked up all the papers the game is still running? Thanks to google i find this script.

Comment
Add comment · Show 4
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 meat5000 ♦ · Jun 24, 2014 at 06:01 PM 4
Share

It's not formatted properly, is what's grong with it.

avatar image meat5000 ♦ · Jun 24, 2014 at 07:23 PM 2
Share

If you see "All Papers Collected" then your script works. There is no other End-Game code aside from this.

avatar image Kiwasi · Jun 24, 2014 at 07:32 PM 1
Share

Its now formatted properly, mainly due to my trigger happiness with my new 2$$anonymous$$ powers.

avatar image Script_Coded · Jun 24, 2014 at 08:28 PM 0
Share

Haha;) You "tagged" me in your script! Got an e$$anonymous$$ail. "@script RecuireComponent ( AudioSource )" But im tired and i can't really read it through now. Srry bro! Ill check on it tomorrow!

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by AlucardJay · Jun 24, 2014 at 08:50 PM

Nothing is grong with the script. I have no idea where you got this version of my script, but for the sake of answering and closing this question, you need to add your own solution for when all the papers are collected. It is clear in the GUI when all the papers are collected. Anyway, here is a more detailed version which clearly indicates what to do when the win condition has been reached :

 #pragma strict
 @script RequireComponent ( AudioSource )
 var papers : int = 0;
 var papersToWin = 5;
 var distanceToPaper : float = 2.5;
 public var paperPickup : AudioClip;
 
 function Start ()
 {
     Screen.lockCursor = true;
 }
 
 function Update ()
 {
     if(Input.GetMouseButtonDown (0) || Input.GetKeyDown (KeyCode.E))
     {
         var ray = Camera.main.ScreenPointToRay(Vector3(Screen.width * 0.5, Screen.height * 0.5, 0.0));
         var hit : RaycastHit;
 
         if(Physics.Raycast(ray, hit, distanceToPaper))
         {
             if(hit.collider.gameObject.name == "Paper")
             {
                 papers += 1;
                 audio.PlayClipAtPoint(paperPickup, transform.position);
                 Destroy(hit.collider.gameObject);
             }
             
             // check if all papers have been collected
             if ( papers >= papersToWin )
             {
                 Debug.Log( "All Papers Collected!" );
                 
                 // ** ADD YOUR WIN CONDITION HERE **
                 // probably load a new scene, eg
                 // Application.LoadLevel( "WinScene" );
             }
         }
     }
 }
 
 function OnGUI ()
 {
     if(papers < papersToWin)
     {
         GUI.Box(Rect((Screen.width * 0.5) -60, 10, 120, 25), " " + papers.ToString() + " papers");
     }
     else
         GUI.Box(Rect((Screen.width/2) - 100, 10, 200, 35), "All Papers Collected!");
 }

For further information, you can watch one of the many videos I have made on collecting papers (and I thought this had stopped haunting me...)

  • Collect papers using Raycast

  • Collect Papers using SphereCast

  • implementation from the new guide

  • new guide full playlist with win and lose scenes near the end

Comment
Add comment · Show 2 · 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 TakUser · Jun 25, 2014 at 11:33 PM 0
Share

Alucard, I wanted to ask you if you could take a look at the coding in my unity file, as the code I used from your code didn't work. The enemy only follows the player if the player has a direct line of sight with the player, and the player interrupts it, but comes back still looking at it. When the player does do that, the enemy slides towards the player and stops when they look away, then look back. If I do need to upload my unity file, keep in $$anonymous$$d it'll be big due to the assets I have.

avatar image Chibli · Jun 27, 2014 at 09:07 PM 0
Share

Alucard thanks, yes i Heard something that you give up about the slender scripts, well thanks dude, the next time i will watch your videos.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

25 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get an object / AI to follow you? 1 Answer

Turning when not seen. 0 Answers

Slender type game 1 Answer

where is a good script to collect pages like in "slender"? 1 Answer

Slender type game need help 0 Answers


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