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 Dimwood2011 · Feb 24, 2014 at 11:40 PM · enable

how to enable and disable script.

This is a baseball game. I have a script called IsGrounded with a boolean.It gets triggered to false which makes another script called fielding become false.This is showing both to be enabled = false,which is what i want.Now fielding i thought would be inactive without the script being checked as true,but it is still active even though it is checked to false. I have read many other things about this in unity answers which says the scripts are still active unless i enable or disable in update,Late update or maybe Start function.how can i change my code for this i dont have update in my fielding script.here my codes

IsGrounded code

 var IsGrounded = false;
 function Update()
 {
     IsGrounded = false;
 }
 function OnCollisionEnter(other:Collision)
 {
     if(other.collider.name == ("Terrain"))
     
         IsGrounded = true;
     
     if(IsGrounded == true)
     {
         gameObject.Find("P_SS").GetComponent("Fielding").enabled = false;
         Debug.Log("Grounded");
     }
 }

fielding code

 function OnCollisionEnter(other:Collision) 
 {
     if(other.collider.name == ("BaseBall(Clone)"))//&& IsGrounded == false)
     {
         Destroy(other.gameObject);
         audio.Play();
     }
 }

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Simeon · Feb 25, 2014 at 01:10 AM

First of all, it will be a good idea to use tags instead of names, and i think the code will go something like this:

 var IsGrounded = false;
 function Update()
 {
     IsGrounded = false;
 }
 function OnCollisionEnter(other:Collision)
 {
     if(other.collider.tag == ("Terrain")){
        IsGrounded = true;

        gameObject.Find("P_SS").GetComponent("Fielding").enabled = false;
        Debug.Log("Grounded");
     }
 }


 function OnCollisionEnter(other:Collision) 
 {
     if(other.collider.tag == "BaseBall") //&& IsGrounded == false)
     {
        Destroy(other.gameObject);
        audio.Play();
     }
 }

and another thing, if you want to destroy objects immediately use:

 DestroyImmediate(obj: Object, allowDestroyingAssets: bool = false):

 
Comment
Add comment · Show 2 · 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 Dimwood2011 · Feb 25, 2014 at 02:06 AM 0
Share

OnCollisionEnter already has a definition.Cant do that.I will try trigger on the second part.I cant use a trigger here it ball will go through the terrain.I put both parts of code in the same OnCollisionEnter.It has the same outcome as my original code.Shows enabled box for terrain as off but yet i can still get collision from fielder.I need fielder code to be true from fielder only when the ball is airborne.Grounded i need fielder code to be shut off.Not sure where to go with this.Basically the fielder is as if he is catching the ball in the air audio.Play(); for an out always, even though the ball has hit the ground first.I need a grounder to be treated as a grounder. ty Dimwood

avatar image Dimwood2011 · Feb 25, 2014 at 07:57 PM 0
Share

anymore ideas?still same result.

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

21 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

Related Questions

How can I enable and disable scripts at runtime? 2 Answers

Enable My Script on Spawn 0 Answers

How do I disable FPS controls and MouseLook controls and Start Getting Mouse Coordinates? 1 Answer

Error when accessing variables from another script: NullReferenceException: Object Reference not set to an instance of an object.. 0 Answers

The best way to trigger game events in a list 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