- Home /
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.
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.
Oh wow, made my day, upped and merry_christmas to you too XD
to $$anonymous$$iri : http://en.wikipedia.org/wiki/Boolean
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...
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?
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.
Your answer
Follow this Question
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