Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

234
Views
enable script when press button in unity

how can I enable and disable script on enemy object when I pressed specific button in unity

void OnButtonClick()
{
    StartCoroutine(Cooldown());
    GetComponent<FollowEnemy>().enabled = !GetComponent<FollowEnemy>().enabled;
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

GetComponent(MyScript).enabled = false;

Might be a good place to start,

For the button a Input.GetKey(KeyCode.Space), would do the trick.

You might need to experiment a bit, you can find more information here:

https://answers.unity.com/questions/26844/enabledisable-specific-components.html

Official documentation:

https://docs.unity3d.com/ScriptReference/KeyCode.html

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!