Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 serdechny · Feb 21, 2019 at 02:22 PM · disableenablevoid

how can I disable and enable a privte void in the same script with a line of a cod

if Im doinig GameObject.Find("swat").GetComponent().enabled = false; so in the next I cant enable it like that GameObject.Find("swat").GetComponent().enabled = true; so what can I do to disable only a void like performMovment() or any other void. please help. (sorry for bad English)

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 zereda-games · Feb 21, 2019 at 02:52 PM 0
Share

are you Invoking it? if so CancelInvoke("$$anonymous$$ethodName"); works for that.

2 Replies

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

Answer by xxmariofer · Feb 21, 2019 at 02:43 PM

hello, you cant disable a "void". void is returned type (which means they dont return a type) the enabled property stops the update calls, if you dont want to call one specific method just dont call it, and if you calling it in the update create a bool for controlling when you call it.

Comment
Add comment · Show 7 · 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 zereda-games · Feb 21, 2019 at 02:53 PM 0
Share

Not sure that's Quite what they meant but good*coment* ;)

avatar image xxmariofer zereda-games · Feb 21, 2019 at 03:12 PM 0
Share

what do you mean by good comment?

avatar image serdechny · Feb 21, 2019 at 03:07 PM 0
Share

so if I want to disable a method how can I do it?

avatar image xxmariofer serdechny · Feb 21, 2019 at 03:12 PM 0
Share

you dont disable methods you just dont call them. if you dont call it it will not get invoked, can you share your code so i can try to give you an example?

avatar image serdechny · Feb 21, 2019 at 03:14 PM 0
Share

using System.Collections; using System.Collections.Generic; using UnityEngine;

[RequireComponent(typeof(Rigidbody))]

public class player$$anonymous$$oto : $$anonymous$$onoBehaviour {

 private Vector3 velocity = Vector3.zero;

 private Vector3 rotation = Vector3.zero;

 private Vector3 cameraRotation = Vector3.zero;
 public Animator Anim;

 public bool run;


 [SerializeField]
 private Camera cam;

 private Rigidbody rb;

 private void Start()
 {

     

     rb = GetComponent<Rigidbody>();

     // Store a copy of your cullingmask
     _mymask = cam.culling$$anonymous$$ask;

     // Only render objects in the first layer (Default layer)
     cam.culling$$anonymous$$ask = 1 << 0;

     // do something

 }

 public void move (Vector3 _velocity )
 {
     velocity = _velocity;


 }

 public void rotate(Vector3 _rotation)
 {
     rotation = _rotation;


 }

 public void rotateCamera(Vector3 _cameraRotation)
 {
     cameraRotation = _cameraRotation;


 }

 private CharacterController controller;
 private float gravity = 14.0f;
 private float verticalVelocity;
 [SerializeField]
 private float jumpForce = 10.0f;


 private void FixedUpdate()
 {

     perform$$anonymous$$ovment();
     prformRotation();

    

     //animations
     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.W)) //forward 1
     {
         Anim.SetInteger("walk", 1);
     }
     else if (Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.W)) //forward 0 
     {
         Anim.SetInteger("walk", 0);
     }
     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.S)) //backward 1 
     {
         Anim.SetInteger("walk backword", 1);
     }
     else if (Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.S)) //backward 0
     {
         Anim.SetInteger("walk backword", 0);
     }
    if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.V))
     {
         Anim.SetBool("dance?", true);
         GameObject.Find("swat").GetComponent<player$$anonymous$$oto>().enabled = false;


     }
   else  if (Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.V))
     {
         Anim.SetBool("dance?", false);
         GameObject.Find("swat").GetComponent<player$$anonymous$$oto>().enabled = true;
     }








 }


 void perform$$anonymous$$ovment()
 {
     if (velocity != Vector3.zero)
     {
         
         rb.$$anonymous$$ovePosition(rb.position + velocity * Time.fixedDeltaTime );
         
     }
 }

 void prformRotation()
 {
     rb.$$anonymous$$oveRotation(rb.rotation * Quaternion.Euler(rotation));
     if (cam != null)
     {
         cam.transform.Rotate(-cameraRotation);
     }
 }

 
 int _mymask;

 
 

}

avatar image xxmariofer serdechny · Feb 21, 2019 at 03:19 PM 0
Share

the easiest solution is to put the perform$$anonymous$$ovment(); line inside the updtae in an if statement like this

 if(wantToPerform$$anonymous$$ovement){
    perform$$anonymous$$ovment();
 }

and when you dont want to perform$$anonymous$$ovment you can just do this

 wantToPerform$$anonymous$$ovement = false;

and the method wont be called and set it again to true for calling it again

avatar image serdechny · Feb 21, 2019 at 03:25 PM 0
Share

ty very much I did x = 4; if(x == 4){ perform$$anonymous$$ovment(); }

x = 2 // stops the moves

avatar image
0

Answer by OscL1 · Aug 06, 2020 at 10:44 PM

You don't disable a method, you just don't call it, say I have a method --> Void A(){Debug.Log("Hi");} --> and I call it in update --> void Update(){A();} --> but I want the console to stop printing out Hi 30 seconds after the games, I can simply add a if statment --> if(Time.time < 30){A();} --> There is also a lot of ways to do this, an if statment is the simplest like you can use a Coroutine or **InvokeRepeatin**g to repeat a method not every frame but a set amout of second that you want it to be, or you can use the switch statment to check on a value, and more and more...

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

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

Related Questions

Enable/Disable Game Object With GUI Button 1 Answer

Enabling loop and disabling loop 1 Answer

Enable/Disable a Static object 1 Answer

How to change settings to a rigidbody when adding it to a gamobject? 2 Answers

Gui.Enable transperancy 4 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