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 Erhan · Nov 13, 2010 at 03:06 PM · instantiateaccess

Instantiated objects accessability

Hello.

In my game, I can "shoot" balls with instantiate function in the script, that is attached to my Character Controller.

To Character Controller is attached another script, which Im trying to use to check if the ball hit the player. I have 2 versions, but they dont work. I think its because of I can do this check only to original Ball and not to its copies. But I dont know how to access them :(

First:

void OnControllerColliderHit(ControllerColliderHit hit) {
    if(hit.gameObject.name == "Gule")
            print("trolololololl");
}

Second:

public Transform Gule;

void OnControllerColliderHit(ControllerColliderHit hit) { if(hit.gameObject == Gule) print("trolololololl"); }

Thank you for your ideas! Erhan

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 Erhan · Nov 13, 2010 at 03:07 PM 0
Share

Gule means "Ball" and "trololololl" is just my check message ^^

2 Replies

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

Answer by Jesse Anders · Nov 13, 2010 at 03:21 PM

Try using tags instead.

Comment
Add comment · Show 4 · 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 Erhan · Nov 13, 2010 at 03:40 PM 0
Share

It didnt help.

avatar image Jesse Anders · Nov 13, 2010 at 03:45 PM 0
Share

'It didn't help' doesn't tell us anything. You haven't told us what changes you've made, so we don't know if your new code is correct, if you've assigned the appropriate tags to the right objects, etc. In other words, you're making it very hard for us to help you :) In any case, the problem (as you seem to suspect) is probably that the clones are not named "Gule". The tag, however, will be the same for any clones as it is for the original, which is why I suggested using tags ins$$anonymous$$d. If that's not working for you, please edit your post to include more information so that we can help you.

avatar image Erhan · Nov 13, 2010 at 04:02 PM 0
Share

Im so noob. Sorry, but I tried to add a tag in code. I realised now, that it would be better to add it in inspector and voila! Thank you! :)

avatar image Jesse Anders · Nov 13, 2010 at 04:20 PM 0
Share

Good, glad you got it working :)

avatar image
0

Answer by Loius · Nov 13, 2010 at 04:29 PM

Every object is different. Storing a reference to one ("public Transform gule") only references that specific one.

When an object is created through Instantiate(), (Clone) is added to its name.

The best way to do this is to give the balls a unique tag or a unique component. You can then use

if ( hit.gameObject.tag == "Tag" )

or

if ( hit.gameObject.GetComponent( ComponentName ) )

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

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

How to access varibles on a newly instantiated object 2 Answers

Access Child of instantiated UI-Prefab using C# in Unity Beta 4.6 1 Answer

access instantiated object variable 0 Answers

accessing an instantiated prefab's components in C#? 2 Answers

Access a instantiated gameobject from a enemy spawner 4 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