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
0
Question by shadowpuppet · May 21, 2015 at 09:17 AM · scripting problem

killing a script from another

I am trying to kill a script from another script. i have seen dozens of examples and tried to alter them to fit my needs with no luck. half the time I get errors from the scripts even without altering them. Here is my situation. i have an enemy with animations and he is following a behaviour script ( called "EnemyBehaviour"). I found it and it works fine.The enemy sees me, runs at me and attacks. and attacks and attacks. I want him to stop by punching him. I also have scripts for that where I can run around and punch other objects to make them animate. What I want is to punch the enemy and have him die - or play an animation called "MiaDie". Now THAT much I can even do - if I turn off the EnemyBehaviour script. With the EnemyBaviour script enabled, I can see he starts to die for a few frames but then the attacking still continues. So I want to add to the script below something to the effect of GetComponent.script.enable = false. Or whatever to stop this guy from hitting me`var KillMia : AnimationClip;

 function OnTriggerEnter (fist : Collider) {
 if(fist.tag=="Fist") 
 GameObject.Find("newmia").animation.Play("MiaDie");

 

 
 }



this is a javascript attached to the miamodel. Is the fact that I am trying to kill a C# script ( EnemyBehaviour) with a javascript an issue? do they not play well together. I Forest Gump my way through programming by using what I find so if anyone has a C# code for thisI'm fine with that

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 applemaniac · May 22, 2015 at 08:55 AM 0
Share

You can add a static boolean to your script, and execute the ennemy's behavior only if your boolean is true. Then, when you kill the enemy, you just have to set this static bool to false.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Baste · May 21, 2015 at 09:35 AM

The easiest thing is to set the script to inactive - that will stop all of the calls to Update. BUT UnityScript ("JavaScript") and C# scripts can't talk together out of the box - so you can't do a GetComponent to find the EnemyBehaviour script.

A UnityScript script cannot "see" C# script unless they're compiled before the UnityScript script. There's a pretty easy way to fix that - you move all of the C# scripts to a folder that compiles earlier (like the Plugins folder), and you're good to go. There's a more thorough explanation here.

That being said, mixing languages is hard. I also find that UnityScript, while having some nice features, actually becomes harder to use once you get into it. There's also not very many resources online about it since it's only used in the context of Unity, and it's also wildly different from the JavaScript that's used everywhere else - so if you google for solutions to "JavaScript" issues, you'll never find an answer that's actually applicable to Unity.

Because of that, I'd suggest you drop UnityScript and stick to C#. In that case, your problem is simple to solve:

 var enemy = GameObject.Find("newmia");
 enemy.animation.Play("MiaDie");
 enemy.GetComponent<EnemyScript>().enabled = false;




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 shadowpuppet · May 21, 2015 at 02:29 PM 0
Share

Sorry posted as answer not comment. i see how this kills the running script and plays the death animation but where is the whole trigger instruction of the "collider tagged "fist" making this all happen - or the C# variation of what I had with the OnTriggerEnter ?

avatar image shadowpuppet · May 21, 2015 at 03:32 PM 0
Share

I'll try That. Thanks for all the info. But just looking at it I am a bit confused. I see it kills the script and plays the death but where is the trigger to set it all in action? The collider tagged "fist". Or the C# version of that?

avatar image Baste · May 22, 2015 at 08:42 AM 0
Share

I just skipped that part, as it's the same thing in both languages. Functions are declared differently, but you'll figure that out on your own.

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

help with animation 1 Answer

Why my editor vs code opens a few windows when i try to open a script from unity,My VS Code open a few tables when i double click a script in Unity? 0 Answers

[Unity5] Performance and functions 3 Answers

How to make script affect only one this game object 2 Answers

Characterdoesn't run on Aiming mode 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