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
0
Question by KiriLucas · Mar 02, 2013 at 03:17 AM · boolean

How to add a script to my script ?

I mean... Someone told me that I should put a boolean to my script, so it would work as I want, but I don't know how (I'm very noob, yes). This is my script:

 var nextLevel : String;
 
  
 
 function OnTriggerEnter() {
 
     //------------//
 
     Application.LoadLevel (0);
 
     //------------//
 
 }


He told me to put this boolean to my script:

 var hasBook : boolean;
 var pos2 : GameObject;
  
 function OnTriggerEnter (other : Collider)
 {
    if(hasBook)
    {
       player.transform.position = pos2.transform.position
    }
 }


Can you made the script for me ? Please don't tell me to learn how to code first, I'm making a SIMPLE game and I want to finish it as soon as possible.

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 ByteSheep · Mar 02, 2013 at 06:12 AM 4
Share
     var askedClearQuestion : boolean = false;
     var codingBook : GameObject;
      
     function OnAskedQuestion (reply : Remark)
     {
       if(askedClearQuestion)
       {
         GiveHelpfulResponse();
       }
       else if(!askedClearQuestion)
       {
         codingBook.transform.position = $$anonymous$$iriLucas.house.address;
       }
     }

I made the script for you..
Don't know if this is what you are looking for but since you didn't explain what you want the script to do, I thought I would be creative and guess! Please explain what you want the script to do and I'm sure someone will find the time to try and help you.

avatar image AlucardJay · Mar 02, 2013 at 07:14 AM 0
Share

Oh wow, made my day, upped and merry_christmas to you too XD

to $$anonymous$$iri : http://en.wikipedia.org/wiki/Boolean

avatar image KiriLucas · Mar 02, 2013 at 03:36 PM 0
Share

Oh, yeah, I forgot... I'll try using the script you made, but I can't now, so I'll try to explain...

I have a portal:

 var nextLevel : String;
  
  
  
 function OnTriggerEnter() {
  
     //------------//
  
     Application.LoadLevel (0);
  
     //------------//
  
 }

I asked someone how to made a "key" to the portal, so, when I pick up the key (a book) it would let me pass trough the portal...

The portal is always there, but until you find and take the key, it would do nothing (the portal is just a plane with a texture).

So basically, I need to put the script he made in my portal, so it will made the book as a key...

avatar image youngapprentice · Mar 02, 2013 at 03:38 PM 0
Share

I;m sorry to be that one guy, but isn't the entire idea of making a simple game to learn how to use basic coding conventions to achieve simple objectives?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Djaydino · Mar 02, 2013 at 04:49 PM

boolean is a true/false statement

so on line 6 it is saying :

if hasbook (your key) is "true" do this.

from what i understand, you have a portal and a player that will enter the portal

if so, you should do something like this :

on the script from the player add :

 static var hasBook : boolean;

then on line 6 of your portal script instead of if (hasbook) you put :

if(player.hasBook == true) { // do something }

"player" should be the script name on you player

then on the book (key) script you should add :

player.hasBook = true;

probably in the ontrigger function.

the "static" in front of the var hasBook makes it accessible from other scripts.

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

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

13 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

When do we need to use Class? 1 Answer

how to create Magnetic repulsion ? 0 Answers

hide object start script 4 Answers

Getting index of the smallest number in a list 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