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
1
Question by Chris 43 · Apr 24, 2011 at 04:11 PM · prefabsobjectsdifferentlinking

Find Script from another script

Ok so i have a 2 game objects, Object A & Object B

Object A is a player controlled character with quite a few scripts attached. Object B is a trigger Zone

On Object A there are 2 animation sets, 1 Unarmed 2 Armed

So when i step over the trigger zone, i have the following:

function OnTriggerEnter (myTrigger : Collider) {

if(myTrigger.gameObject.name == "Player"){

GetComponent(Unarmed).enabled = false;

GetComponent(Armed).enabled = true;

}}

Now when i do a debug test to see if its detecting the collision all works well. Basically the Armed script starts off inactive and when i touch the trigger zone i want it to disable and enable 2 scripts. It doesn't seem to work, I see it as i need to somehow link scripts between 2 seperate prefabs or objects, How can i do this? Thanks in Advance.

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 MC HALO · Apr 24, 2011 at 04:12 PM 0
Share

right i have to ask the other two scripts are they attached to the same player or other objects?

avatar image MC HALO · Apr 24, 2011 at 04:39 PM 0
Share

See if the answer that i have posted it might help you :)

2 Replies

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

Answer by MC HALO · Apr 24, 2011 at 04:37 PM

Ok say for example you have a player right and on this player you have 5 scripts, now in the game you also have 3 other players with 2 scripts. now you said if you step on the trigger you disable one script and enable the other. because i don't know if these scripts are all attached to your player i will still give you an answer that can help :

function OnTriigerEnter (hit: Collider) {

if(hit.gameObject.tag =="Player"){

          // this will disable the script on the player 
         GameObject.Find("Player").GetComponent("put the script name here ").enabled = false;

                // this will enable the script on the enemy  
                 GameObject.Find("Enemy1").GetComponent("put the script name here ").enabled = true;

                  // this will enable the script on the enemy 
                     GameObject.Find("Enemy2").GetComponent("put the script name here ").enabled = true;


    }

  }

Now basically all you need to do is tell the script what gameOject it should look for the script on and then which script is should enable and disable

i hope this help :)

Comment
Add comment · Show 6 · 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 Joshua · Apr 24, 2011 at 04:42 PM 1
Share

Yep, that's the way. Just keep in $$anonymous$$d that GameObject.Find isn't very realiable. If you know in advance what object's you'll be referencing, just add them in manually using var Player : GameObject;, etc.

avatar image MC HALO · Apr 24, 2011 at 04:48 PM 0
Share

Yep that's true Joshua find is not very reliable. i totally agree with you make them in to a variable and then do the rest this way its a lot better because sometime people forget there tags this way all you have to do is drag and drop the right object in the inspector mode and just cal:)l them :) very good comment

avatar image Chris 43 · Apr 24, 2011 at 05:19 PM 1
Share

Works great thats exactly what i was looking for, thanks very much :)

avatar image MC HALO · Apr 24, 2011 at 05:20 PM 0
Share

your most welcome :)

avatar image TechnoRazor · Dec 28, 2014 at 02:51 PM 0
Share

I tried that and it said there was no such thing as 'enabled.' I thought maybe you mistaked it for active, but even though it existed. that didn't work either. Are you using C# or JS?

Show more comments
avatar image
1

Answer by Joshua · Apr 24, 2011 at 04:24 PM

As MC HALO said, we need to know what the referenced scripts are attached to. If they are not on the gameObject the script you posted is executing from - then that's what you're doing wrong. The script now searches the game object it's attached to for components it does not have.

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 Chris 43 · Apr 24, 2011 at 04:35 PM 0
Share

Yeh Components are both on seperate items Object A has both animation scripts while Object B only has the trigger script So how can i link them?

avatar image Joshua · Apr 24, 2011 at 04:41 PM 1
Share

Looks like HALO just answered that :)

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

1 Person is following this question.

avatar image

Related Questions

affecting only one Prefab in Code. (script) 1 Answer

Is a clone object still a (clone) if you change the name of it using script? 1 Answer

Moving Objects along a vertices 1 Answer

Why does one script not work on multiple gameobjects? 3 Answers

creating a linked object mesh 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