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 Makenshi · Jan 26, 2011 at 08:36 PM · beginnernullreferenceexceptionassign

Passing Values/Variables between Classes

Ive been checking the help of unity and cant find what im looking for so im here XD sry if i just didnt knew how to search and it was there(if thats the case) im working in javascript btw ok the question is i have 3 objects top object bottom object mid object(i just made this to get the variables of the top and bot) ok the thing is when your mouse enters the top object this happens

function UpTrue(Enter:boolean)
{
if(Enter)
{
Count +=1;
}
else
{
Count =0;
}
}

count is declared like this at the top

var Count: int =0;

its the same for bottom so i was making this at the mid one thats the class taking all the info or at least suppossed to

var targetHand: GameObject; var Up : MouseEnterUp;//name of script var Bottom : MouseEnterBottom;//name of script function Start(){ targetHand= GameObject.Find("Hand"); }

function Update() { if(Up.Count >= 1) { targetHand.animation.wrapMode = WrapMode.PingPong; targetHand.animation.Play("clean"); // name of the animation clip } }

so what im trying to do basically is getting Count from object at top and bottom and if they are both 1 or at least for now if top is = 1 then play the animation in case it helps im getting the error NullReferenceException: Object reference not set to an instance of an object MidObject.Update() MidObject is the name of the script attached to the middle object

please any help would be really appreciated if you dont understand anything tell me and i will try to make it better so you can understand :S thank you very much\

since it seems like its kinda hard or something i dont know if theres a way to know the value of a function from other script >.< if theres anything tell me please thank you

Comment
Add comment · Show 1
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 Makenshi · Jan 26, 2011 at 11:28 PM 0
Share

To make it a little clear i want to make this if i made it in c++ it would be public bool UpTrue(Enter) { return Enter; }

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Jan 26, 2011 at 10:52 PM

If I followed your question correctly, it sounds like Up is not assigned to a particular object. Unless the Up script is in the Plugins folder, you'll want to either assign it by GameObject.Find("you object with up script on it"); or drag/drop in the Inspector the object onto that Up variable.

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 Makenshi · Jan 26, 2011 at 11:12 PM 0
Share

well Up And Bottom are both in a different object so parenting them is not really the answer ive been looking for :S because with Find i dont know if you can use it to get the value of a function inside of the script :S i will try it anyways ty

avatar image DaveA · Jan 27, 2011 at 12:59 AM 0
Share

I don't mean parenting in the Hierarchy, but dragging the object onto the variable name in the Inspector, which may not even work. Use Find. Once you find the the object, use GetComponent to get the script, then you can access any public variables it has.

avatar image
0

Answer by kennypu · Feb 12, 2011 at 12:36 AM

its because you declare Up and Bottom, but you never initialized it. so you're doing the same thing as var aNumber:int; but never set it to anything. Assuming that Up and Bottom is attached to the current gameobject, just put this in the Start()

function Start()
{
  Up = gameObject.GetComponent("MouseEnterUp");
  Bottom = gameObject.GetComponent("MouseEnterBottom");
}
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

No one has followed this question yet.

Related Questions

Problem for moving an object with a button 0 Answers

NullException Error With Array of GameObjects 2 Answers

Not sure why I keep getting a Null Reference Exception? (Networking) 0 Answers

Assignment working in Update() but not in Start()? 1 Answer

NullReferenceException even though I assigned it? 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