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 GuilhermeAbeL · Mar 22, 2014 at 11:01 PM · raycastreturngenerics

Raycast return script of hit object (C#)

Hi! I'm a begginer at coding, so don't kill me if this is a stupid question and don't answer with "advanced" coding either, please. I'm trying to make my player cast a ray and, when it hits any gameobject that has a script, make it run.

For example: My character look at a door, turning its script enabled. My character look at a key, turning its script enabled and so on...

I know that it is possible to write something like: GameObject.GetComponent().enabled = true;

But I want something generic, something more like: GameObject.Scripts.enabled = true; (I know that this doesn't lol)

Is there any basic solution? Any suggestion? Thanks for the attention.

Comment
Add comment · Show 5
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 getyour411 · Mar 22, 2014 at 11:02 PM 0
Share

You'll probably regret this later, but you can adapt something like this

  $$anonymous$$onoBehaviour[] scripts = gameObject.GetComponents<$$anonymous$$onoBehaviour>();
 foreach($$anonymous$$onoBehaviour script in scripts)
 {
 script.enabled = false;
 }

If you go this route, you'll probabyl want to add additional logic like if script.name = "VeryImportantOne" don't disable it, etc.

avatar image GuilhermeAbeL · Mar 22, 2014 at 11:13 PM 0
Share

Thanks for commenting! Will try this later cuz I'm about to go out, but... Why will I probably regret this later? If this is a true statement, I don't know if I want to do this...

avatar image Murkas · Mar 22, 2014 at 11:48 PM 0
Share

You could regret this, because later there could be scripts you don't want to enable.

avatar image GuilhermeAbeL · Mar 23, 2014 at 07:45 PM 0
Share

Oh... Reading now the answer given by getyour411 I understood it. Yeah, and don't think this will be worth it... Hmm... But thanks anyway!

avatar image GuilhermeAbeL · Mar 23, 2014 at 08:15 PM 0
Share

Like... It is going to be an adventure game, but not a point and click one, it's gonna be more like a Luigi's $$anonymous$$ansion game, where you can interact with some stuff in the scenario. Some of them will just have a feedback animation (also to entertain), some will display messages or images on the screen, others will be items that you can get and carry through the game etc. I started doing things using trigger, but I could open a door looking at the wall, just cuz I was inside the trigger. Then I decided to use raycast ins$$anonymous$$d, was it a good decision? And, so far, there is just one code attached on the player managing almost everything (like, if the raycast return a gameobject with the name "keyOne", it will change the interface texture of the slot one or two and diplay the keyOne texture, the gameobject will change its position to look like it's gone and you won't be able to get it again etc).

Thank you all guys for everything so far!

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by SkaredCreations · Mar 22, 2014 at 11:37 PM

Honestly it's a strange request to enable ALL scripts (in which case the only way has been suggested by getyour411 in the comment to your topic), I'd suggest to create a basic script for example YourBaseClass (even empty, no variables/methods) that you will inherit in the scripts that you want to target and then use GetComponents of YourBaseClass (it will return both YourBaseClass and inherited scripts)

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

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

what is the problem of my raycast object finder script? 1 Answer

Trouble Rendering Mesh 0 Answers

Custom Collision Detection 4 Answers

physics2d.raycastall help please 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