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 Nhjufy · Feb 25, 2013 at 07:49 PM · materialobjects

Scripting - Refering Pre-Made Objects

I'm stuck at my game and I need help....I looked around and I couldn't find answer to this anywhere. I know how I can modify for example a cube if I created it in script, but I have no idea how can I change it if I haven't created it in script, if I made it outside a script (like a map)... So my question is how can I modify a gameobject (in script) I created using unity without any scripting?

P.S. One more question, it's similar to last one. I have a cube in game, i have a new material. How can I change the cube's material to that new material? :) (script)

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by nsxdavid · Feb 25, 2013 at 11:13 PM

One way is by wiring up a reference to the object.

Create a public variable in a behavior script of a type that you want to reference. The simplest is a GameObject.

So like:

 public GameObject thingIWantToChange;

Now if you select the object with the behavior you created that has this, you'll see a property called "Thing I Want To Change". You can then drag-n-drop any gameobject from the Hiearchy into the slot next to it. You've wired the two together!

Now you can manipulate thingIWantToChange all you want. Like thingIWantToChange.transform.position = new Vector3(10,10,10);

If you don't want to prewire, you have options like Find().

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 kaitou · Feb 26, 2013 at 01:43 PM 0
Share

And to give you your second answer your looking for

 thingIWantToCahnge.renderer.material.SetTexture( "_Texture", yourtexturehere);

 

Where yourTexture here can be anything. I suggest do antother call like he says

 publix Texture yourtexturehere;

so you can set it from the inspector.

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

11 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

Related Questions

Material doesn't have a color property '_Color' 4 Answers

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

Serialize Texture3D 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

getting an object to stick to terrain in 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