Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Tappo · Nov 27, 2014 at 08:24 PM · transformpositionhowenddrawer

How to stop a script in c#

i want that after the closet goes forward the script ends so that when you press e again the drawer won't move, ho can i do this, the sctip s this one:

using UnityEngine; using System.Collections;

public class Drawer : MonoBehaviour {

 public bool inTrigger = false;
 public GameObject Closet;

 void OnTriggerEnter (Collider Other){
     if(Other.tag == "Player"){
         inTrigger = true;
     }
 }
 void OnTriggerExit(Collider Other){
     if(Other.tag == "Player"){
         inTrigger = false;
     }
 }
 void OnGUI (){
     if(inTrigger == true){
         GUI.Box(new Rect (500,300,150,25),"Press E to open");
     }
 }
 void Update (){
         if(inTrigger == true){
         DrawerMovement();
         }
     }
 void DrawerMovement(){
     if(Input.GetKeyDown(KeyCode.E)){
         transform.position = Closet.transform.position - Vector3.left* 1f;
     }
 }

}

Comment
Add comment · Show 2
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 koray1396 · Nov 27, 2014 at 08:29 PM 2
Share

use a boolean, such as. this is highly simple, just to show you how it can be made, and you should be checking this boolean in other parts of the script, where necessary.

 bool drawerOpen = false;
 
 void Drawer$$anonymous$$ovement(){
     if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.E) && !drawerOpen){
         transform.position = Closet.transform.position - Vector3.left* 1f;
         drawerOpen = true;
     }
 }
avatar image robertbu · Nov 27, 2014 at 08:42 PM 1
Share

If you never want to execute this script on this object again, you can Destroy it:

  Destroy(this);

If you just want to turn it off for awhile, then @koray1396's use of a boolean is the way to go.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by sillyjake · Nov 27, 2014 at 11:29 PM

public bool scriptActive;

if (scriptActive) {

}

Put this in all your functions, And you can have a bool toggle it on and off.

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
avatar image
0

Answer by Tappo · Nov 28, 2014 at 12:40 AM

thanks, but i fixed in a easyer way, by deleting the collider after the end of the script, but thanks to all of u

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Need enemy to follow only active character 0 Answers

Drawing a (debug) line between anchored UI element and mouse? 0 Answers

I need help with the location of instatiated objects on the scene and correct interaction with this 2 Answers

How to move an object to your current positon? 0 Answers

How to calculate the distance between specific side of an object and the closest to it surface's edge 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