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 /
  • Help Room /
avatar image
0
Question by YewyHewy · Aug 30, 2016 at 02:17 PM · getcomponentscriptingbasicsvalues

How to access a script/script value from the GameObject

Sorry if this has been answered before, or if its just a dumb question in general. I can't find anything related to it...

Here is my issue. Say I have a camera with the default Tilt Shift script, and when I aim my sights down, it increases the blur amount. They are both on the exact same GameObject. I know you can do some GetComponent tricks to get it, but how do I actually alter these values?

I assume I will have to create a second one with high blur, and just activate and deactivate it when aiming my sights. It would be nice if I could set-up some type of gradual change however.alt text

So in general, I want to directly change a scripts value, from another script, on the exact same GameObject. I'm brand new, so sorry again if it's simplistic and easy to do...

photoone.png (437.1 kB)
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
2

Answer by etaxi341 · Aug 30, 2016 at 02:24 PM

You could acces the Script "TiltShift" in your own Script for aiming. There you can just change the value of the blur area.

so you have to get the Script like this:

 TiltShift ts = GetComponent<TiltShift>();

and then acces the value:

 ts.blurArea = yourValue;

and thats it

Comment
Add comment · Show 7 · 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 YewyHewy · Aug 30, 2016 at 02:50 PM 0
Share

Thank you, but the issue still lies

It throws errors, and tells me i'm trying to access a destroyed object alt text

screen-shot-2016-08-30-at-104939-am.png (47.5 kB)
avatar image etaxi341 YewyHewy · Aug 30, 2016 at 03:19 PM 0
Share

Can you show a bit of your code where you are accessing it? Are you maybe defining the TiltShift instance outside of the method you are using it?

avatar image YewyHewy etaxi341 · Aug 30, 2016 at 03:29 PM 0
Share

alt text

Same object, which is "Gun Camera"

screen-shot-2016-08-30-at-112741-am.png (97.8 kB)
screen-shot-2016-08-30-at-112710-am.png (100.7 kB)
avatar image etaxi341 · Aug 30, 2016 at 03:38 PM 1
Share

Ohh I see whats wrong. You have to define the TiltShift outside of a method and then assign it in Start()

 TiltShift ts;
 
 void Start()
 {
     ts = GetComponent<TiltShift>();
 }
avatar image YewyHewy etaxi341 · Aug 30, 2016 at 03:45 PM 0
Share

Still throws the exact same error.

I looked in the TiltShift code , and saw it had no public class. When I add it in however, it breaks it in another way

avatar image etaxi341 YewyHewy · Aug 30, 2016 at 03:48 PM 1
Share

What error do you get after setting it public?

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

GetComponent public float 1 Answer

I can't access other scripts from the main script - c # 0 Answers

Get() and Set() values of a gridArray from another scipt 0 Answers

attleshipAI.cs(65,90): error CS0176: Static member `battleshipSide.Underattack' cannot be accessed with an instance reference, qualify it with a type name instead 1 Answer

How would I access a property of another objects child component? 2 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