Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Jeroen 1 · Apr 12, 2010 at 08:21 PM · stringcubeextend

Extend from box. Notes

I need to program a game in which you can pick-up notes. I want to make a class that extends from Cube gameobject and add a variable noteText to it. I am new to unity so I have no idea whatsoever on how to do this. Can someone give me a hint?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Molix · Apr 12, 2010 at 09:06 PM

You won't extend from cube; you'll create a script (which extends from MonoBehaviour) and then attach it to any object (like a cube).

e.g. (C#)

public class PickupNote : MonoBehaviour { public string noteText = "";

public void OnTriggerEnter( Collider col ) { // check if other object is a player // e.g. if( col.gameObject.tag == "Player" )

 Debug.Log("You picked up a note: " + noteText);
 Destroy(gameObject);  // kill the pickup object now that you have the note

} }

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 Jeroen 1 · Apr 12, 2010 at 09:46 PM 0
Share

Yes but ehmm I want a note with variable text... I want to create like a new note ( var note :PickupNote = new PickupNote("This is a test"); ) Like that...

avatar image straydogstrut · Apr 13, 2010 at 12:46 AM 0
Share

If you look at $$anonymous$$olix's code above you will see that he has in fact declared a variable called noteText to hold a String for the content of the note.

I don't use C# myself, but you would likely access that variable just like any other. You would have to look at a C# equivalent of Accessing Other Gameobjects (http://tinyurl.com/y2a7qyw) if you are addressing the variable from another script on another gameObject.

avatar image
-1

Answer by Jeroen 1 · Apr 12, 2010 at 11:21 PM

Yes but ehmm I want a note with variable text... I want to create like a new note ( var note :PickupNote = new PickupNote("This is a test"); ) Like that..

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 straydogstrut · Apr 13, 2010 at 12:47 AM 0
Share

Also, it is bad form to post follow up questions as an Answer. If you have a query, post a comment or make edits to your question.

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

Create Texture2D and assign image to it through a script 1 Answer

Webplayer String length fails? 1 Answer

Create a list of all PlayPref Keys 2 Answers

Using Application.OpenUrl to open a URL in a String variable 1 Answer

Split a string every 'n' characters? 5 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