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 Jesus_Freak · Nov 15, 2010 at 08:38 PM · playerswitchhelicopteraircraft

switching scripts on and off

here's what i need it for: you walk around the level, and when you hit a helicopter in the game, i have it where it turns off the script used to move a player so that when you're in the helicopter, you can't control movement of the main player.

that works and all, but i want to be able to actually turn on the MoveAround script after the helicopter hits it's end trigger. right now, it's not re-enabling that script...

here are my scripts to control this:

this script is titled: "PlayerHeliPlayer"

var Cam1 : Camera;//player camera var Cam2 : Camera;//heli camera main var Cam3 : Camera;//heli camera move-able static var fly = false;//am i flying yet?

function OnTriggerEnter(hit : Collider) { if(hit.gameObject.tag == "endFlight")//to stop flying { Cam1.enabled = true; Cam2.enabled = false; Cam3.enabled = false; } }

function Update () { if(fly)//if i am (supposed to be) flying... { Fly(); } }

function Fly() {//make me fly! transform.Translate(Vector3.forward Time.smoothDeltaTime 100); }

and that obviously makes the heli move. this script goes on the player and turns off the MoveAround script it's titled: "PlayerCall"

static var Walk = true; static var WALK = false; var camera1 : Camera; var camera2 : Camera; var camera3 : Camera;

function Start() { camera1.enabled = true; camera2.enabled = false; Walk = true; WALK = false; }

function OnTriggerEnter(hit : Collider) { if(hit.gameObject.tag == "Heli") { PlayerHeliPlayer.fly = true; camera1.enabled = false; camera2.enabled = true; camera3.enabled = true; Walk = false; WALK = false; } }

function Update() { MA = GetComponent(MoveAround); if(Input.GetKeyUp("escape")) { Application.LoadLevel("Main Menu"); } if(Walk && gameObject.tag == "Player") { MA.enabled = true; } else {MA.enabled = false;} }

those script work fine together to turn off the MoveAround script... but apparantly i don't know the correct way to turn a script back on... so could you please help me?

in case you need my MoveAround script (you shouldn't but), here it is:

//shooting static var UseBetterBullet = false;

//dying static var dead = false; static var Dead = false; private var Respawn = true; static var money = 0; static var SCORE = 0;

static var Player1 = true; var bullitPrefab : Transform; var respawn1 : Vector3; var respawn2 : Vector3;

static var DSN = false;

//geting hit static var gotHit = false; static var IsPlayer = true;

function Start() { particleEmitter.emit = false; }

//respawn function LateUpdate() { if(DSN) {
// activates the game object. gameObject.active = true; } if(Dead && !Respawn) { transform.position = respawn2; Dead = false; print("i respawned yet again!"); } if(dead && Respawn) {//where the player respawns transform.position = respawn1; dead = false; print("i respawned!"); } }

function OnTriggerEnter( hit : Collider ) { if(hit.gameObject.tag == "SuddenDeath1") { enemyFollow.MOVE1 = false; enemyFollow.MOVE2 = false; enemyFollow.MOVE3 = true; }

if(hit.gameObject.tag == "TurretSlaught2") { enemyFollow.MOVE1 = false; enemyFollow.MOVE2 = true; enemyFollow.MOVE3 = false; }

if(hit.gameObject.tag == "MoneyMaker") { money += 50; Destroy(hit.gameObject); print("I have " +money+ " Dollars!"); }

if(hit.gameObject.tag == "fallout3" && !Respawn) { Dead = true; HealthControl.LIVES -= 1; } if(hit.gameObject.tag == "fallout2") { Respawn = false; } //when the player falls off (this doesnt really work too good. ) if(hit.gameObject.tag == "fallout") { dead = true; //subtract life here HealthControl.LIVES -= 1; print("i fell off..."); }

//getting hit (this works) if(hit.gameObject.tag == "enemyProjectile") { gotHit = true; HealthControl.HITS += 1; Destroy(hit.gameObject); print("i got hit!"); } //manipulating weather if(hit.gameObject.tag == "weather") { ParticleEmitToggle.WCONTROL = true; print("Now i can control weather."); } //level select button controls if(hit.gameObject.tag == "Level2") { GUIshader.Level2 = true; print("hit level two"); }

if(hit.gameObject.tag == "Level3") { GUIshader.Level3 = true; print("hit level three"); }

if(hit.gameObject.tag == "Level4") { GUIshader.Level4 = true; print("hit level four"); }

if(hit.gameObject.tag == "Level5") { GUIshader.Level5 = true; print("hit level five"); }

if(hit.gameObject.tag == "WORK") { MovingPlatform4.work = true; } }

/// This script moves the character controller forward /// and sideways based on the arrow keys. /// It also jumps when pressing space. /// Make sure to attach a character controller to the same game object. /// It is recommended that you make only one call to Move or SimpleMove per frame.

var speed : float = 6.0; var jumpSpeed : float = 8.0; var gravity : float = 20.0;

private var moveDirection : Vector3 = Vector3.zero;

function Update() {

var controller : CharacterController = GetComponent(CharacterController); if (controller.isGrounded) { // We are grounded, so recalculate // move direction directly from axes moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed;

//jumping if (Input.GetButton ("Jump")) { moveDirection.y = jumpSpeed; print("I'm jumping!"); } }

// Apply gravity moveDirection.y -= gravity * Time.deltaTime;

// Move the controller controller.Move(moveDirection * Time.deltaTime);

//main menu button if(Input.GetKeyDown("escape")) { Application.LoadLevel("Main Menu"); print("Main Menu Loading..."); }

//shooting if(Input.GetKeyDown("f") && !UseBetterBullet && !Player1) {//makes a fireball prefab var bullit2 = Instantiate(bullitPrefab, gameObject.Find("SPawnPoint").transform.position, Quaternion.identity);

 bullit2.tag = "wormProjectile";
 //shoots it forward
 bullit2.rigidbody.AddForce(transform.forward * 4000);
 //makes it go completely straight
 useGravity = false;
 print("I shot a fireball!");
 }

if(Input.GetKeyDown("f") && !UseBetterBullet && Player1) {//makes a fireball prefab var bullit = Instantiate(bullitPrefab, gameObject.Find("spawnPoint").transform.position, Quaternion.identity);

 bullit.tag = "wormProjectile";
 //shoots it forward
 bullit.rigidbody.AddForce(transform.forward * 4000);
 //makes it go completely straight
 useGravity = false;
 print("I shot a fireball!");
 }

if(Input.GetKey("f") && UseBetterBullet) { particleEmitter.emit = true; Invoke("DestroyEmitter",1); }

 //prints your score

print("Score: "+SCORE); //changes your score switch(SCORE) { case 10: Application.LoadLevel("Main Menu"); break; }

} function DestroyEmitter() { if(Time.time*1.5 > 7.5) particleEmitter.emit = false; }

 @script RequireComponent(CharacterController)

Thank You in advance!!!

Comment
Add comment · Show 1
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 Jesus_Freak · Nov 15, 2010 at 08:41 PM 0
Share

the "PlayerHeliPlayer" script goes on the helicopter, and the "PlayerCall" goes on the player. and the $$anonymous$$oveAround script goes on the player.

i didn't think that was clear enough in my question.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Jesus_Freak · Nov 15, 2010 at 08:53 PM

Well, i fixed it. Yay! here's what i did:

at the bottom of my "PlayerCall" script, i added this piece of code:

@script RequireComponent(MoveAround)

and because that probably isn't what fixed it, here's what i think fixed it:

In the "PlayerHeliPlayer" script, i added this in the "if(hit.gameObject.tag == "endFlight")" code:

  PlayerCall.Walk = true;
Comment
Add comment · Show 3 · 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 Jesus_Freak · Nov 15, 2010 at 09:00 PM 0
Share

as soon as i posted my Q, i noticed that i didn't have anything to turn $$anonymous$$A back on, or Walk back to true. silly scripting mistakes like that... happen to me frequently. but it's good i at least know when i mess up, right?

avatar image JesusChristChangedMe · Nov 17, 2010 at 01:07 AM 0
Share

you could just make a static var in your move around script and have it say if blah,blah,blah is true then under that have the players movement code. so when you hit the heli then say something like $$anonymous$$oveAround.$$anonymous$$OVE = false; and make sure at the beginning $$anonymous$$OVE or whatever you name it is true; so your player can move around. Hope That Helps!

avatar image Jesus_Freak · Nov 18, 2010 at 07:44 PM 0
Share

that's what PlayerCall.Walk was made for. so, thanks.

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

No one has followed this question yet.

Related Questions

How to switch and unlock game characters in real time 0 Answers

Weapon switching problem 1 Answer

Two player cannonball scene, need scripting help 1 Answer

How do you switch scenes? PLZ HELP!!! 3 Answers

switch player and npc follow player 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