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 Punkjim420 · Jan 30, 2014 at 09:39 AM · c#customtypesget component

how to create a custom type in C#? public Atype atype;

Ive seen other people make there own types in scripts like this..

 private AnotherScript anotherScript;
 private YetAnotherScript yetAnotherScript;
 private BoxCollider boxCol;

yet when i try to do this i get errors that they arent real types. how can i make them usable types?

i want to do:

MyScript myscript = target.GetComponenet();

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 TheYokai · Jan 30, 2014 at 09:51 AM 2
Share

Firstly, you must make a new class in a new script file called $$anonymous$$yScript that has it's definition / declaration.

Secondly, I believe "GetComponent" method requires you inputting a type. I believe you'd want to do target.GetComponent($$anonymous$$yScript)? I'm not sure what you're trying to achieve, so I'm kind of just guessing.

You may need to provide more code. I'm not sure if you've even made a $$anonymous$$yScript class at this point, so it's hard for me to help you figure out why you can't have "usable types". Are you getting an error upon compilation? Is this an editor script you're working on? $$anonymous$$ore info would be nice before a finalized answer.

avatar image Punkjim420 · Jan 30, 2014 at 10:21 AM 0
Share

i have not made any new classes.

target.GetComponent($$anonymous$$yScript); was indeed what i wanted to do.

I need a method for calling a script in GetComponent, then using the variables in the script i called like so:

target.GetComponent(ScriptINeedToGet);

ScriptINeedToGet.VariableIWantToChange = NewValue;

1 Reply

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

Answer by CostelloNicho · Jan 30, 2014 at 11:27 AM

 ScriptYouNeed script = target.GetComponent<ScriptYouNeed>();
 script.VariableToChange = SomeValue;

or

 target.GetComponenent<ScriptYouNeed>().VariableToChange = SomeValue;
Comment
Add comment · Show 3 · 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 Punkjim420 · Jan 30, 2014 at 12:38 PM 0
Share

int targetHp = target.GetComponenent(Player).playerHp;

this errored, any idea why? error log is CS1061: Type UnityEngine.GameObject' does not contain a definition for GetComponent' and no extension method GetComponent' of type UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)

avatar image Punkjim420 · Jan 30, 2014 at 12:41 PM 0
Share

and i apologize, i marked this question as answered by mistake earlier, i undid that though, since i still do not understand.

avatar image Punkjim420 · Jan 30, 2014 at 01:35 PM 0
Share

i figured it out, i was trying to find a script of a seperate type.. int targetHp = target.GetComponenent (); should have been..

Player = target.GetComponenent ();

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

20 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

C# Custom Collision Script (solved) 1 Answer

How to sort get components? 3 Answers

How to put specific shapes/textures instead of generating colors (C#) 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