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 Aldwoni_legacy · May 10, 2011 at 10:55 AM · javascriptboolean

how to know which script you change?

How do I know I changed the right script.

I have 4 objects which all have an script called "Item" attached.

function OnCollisionEnter(collision : Collision) { kind = collision.gameObject; }

function LatenVallen(){ if(kind != null) { var fixJoint = kind.GetComponent(FixedJoint); Destroy(fixJoint); kind.gameObject.rigidbody.useGravity = true; grens = false; script = kind.GetComponent(Item); script.valtaan = true; kind = null; }

How can I change the boolean of Item1 and then use the boolean in Item1. Currently, after I changed the boolean of Item1, Item3 uses it to activated a function which changes the boolean back to false.

I justed named them Item1, Item2, Item3 and Item4 instead of 4x Item.

Comment
Add comment · Show 4
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 CHPedersen · May 10, 2011 at 11:57 AM 0
Share

This ultimately depends on the GameObject stored in kind. Are all GameObjects to which Item is attached instants of the same prefab? How are you selecting the one whose Item-script you want to access the boolean in?

avatar image Aldwoni_legacy · May 10, 2011 at 12:03 PM 0
Share

the GameObjects are duplicates of eachother, but I gave them the Item.js after i made them. No prefabs used. Used the OncollisionEnter to decide which gameobject to use

avatar image CHPedersen · May 10, 2011 at 01:05 PM 0
Share

Ahh, I see. Check my reply below, then. :)

avatar image Aldwoni_legacy · May 10, 2011 at 01:36 PM 0
Share

the problem is that I don't want to specify which Item to take. I have a character who can grab and drop. As soon as he drops something. the boolean of the item which is dropped must become true.

3 Replies

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

Answer by CHPedersen · May 10, 2011 at 01:05 PM

If you're not using prefabs but have manually created 4 objects in the editor and then given them the same script, then you can identify them by their name, assuming you've also given them different names.

The Collision-object passed as an argument in OnCollisionEnter contains information on which GameObject you've collided with. Then you can check the name of the GameObjects involved in the collision to see which GameObjects and consequently, which versions of Item you're accessing booleans in.

Edit: You're kind of doing that already. If you have

function OnCollisionEnter(collision : Collision) {
kind = collision.gameObject;
if(kind.name == "[Whatever name you've given the first GameObject]") 
    // If true, you're accessing the first version of Item
}
Comment
Add comment · Show 1 · 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 Aldwoni_legacy · May 16, 2011 at 10:36 AM 0
Share

I some used a static which created the problems.

avatar image
-1

Answer by bob 7 · May 10, 2011 at 03:41 PM

its possible, :)

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

Answer by Jean-Fabre · May 10, 2011 at 11:22 AM

Hi,

If you have more than one component, use GetComponents ( which returns a list of components) and then in each component you have to maintain a variable to differentiate them somehow and check against that. Else call the method in each.

Bye,

Jean

Comment
Add comment · Show 1 · 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 Aldwoni_legacy · May 10, 2011 at 11:41 AM 0
Share

I only have one component called "Item" but I have multiple times, the same script attached to different objects.

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

No one has followed this question yet.

Related Questions

Take boolean from other script error 1 Answer

Can someone translate C# to Javascript? 2 Answers

How to make a N-S magnet Javascript? 1 Answer

How do I make a sword swing? 2 Answers

Compiler error UCE0001: ';' expected 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