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
-1
Question by Delequiox · Aug 16, 2012 at 01:00 AM · variablegetcomponentboolean

Getting Variable value from another object?

Anyone know how to fix this issue? (Java) Here's the part I'm stuck at. I'm trying to find a variable name from a different object (Object is the player, script on it is called "PlayerAnimationController") I'm looking for the variable called "Facing" in said script. Then check if the Facing Variable is 0 (Left) or 1 (Right). But I'm having trouble accessing it. My error is:


Assets/SamuraiScroller/Scripts/EnergyBar.js(83,70): BCE0020: An instance of type 'PlayerAnimationController' is required to access non static member 'Facing'. _

Code snipet of the problematic area:


 if (Active == 2){
 
 var Facingscript : PlayerAnimationController;
 Facingscript = GetComponent("PlayerAnimationController");
 
 audio.clip = ReleaseSound;
 audio.Play();
 var Spawnpoint = GameObject.Find("Special_Attack_Spawn");
 var ChargeAttack = Instantiate(SpecialAttack, Spawnpoint.transform.position, transform.rotation);
 
 if(PlayerAnimationController.Facing == 0)
 {
 ChargeAttack.rigidbody.AddForce(Vector3.Left * AttackSpeed);
 }
 if(PlayerAnimationController.Facing == 1)
 {
 ChargeAttack.rigidbody.AddForce(Vector3.Right * AttackSpeed);
 } 
 Active = 1;
 yield WaitForSeconds (audio.clip.length);
 Active = 0;
 }
 }
Comment
Add comment · Show 3
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 DaveA · Aug 16, 2012 at 01:04 AM 3
Share

This is THE $$anonymous$$OST AS$$anonymous$$ED QUESTION EVER! I see it at least twice a day. Anyone wanna explain 'the reference manual' and using 'search' here? I'm tired.

avatar image Kryptos · Aug 16, 2012 at 01:06 PM 0
Share

This kind of question should not pass moderation.

To moderators (such as myself): there is a "send message" option along "publish". It can be used to notify the user, so please use it.

avatar image kobebeef415 · Jul 10, 2013 at 06:39 AM 0
Share

I've searched for it for hours and no one really explains it they just send you to the reference manual

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Seth-Bergman · Aug 16, 2012 at 01:42 AM

Ok, here's the deal:

 Facingscript = GetComponent("PlayerAnimationController");

 

first off, this will return type of "Object" rather than "PlayerAnimationController" like you want

 Facingscript = GetComponent(PlayerAnimationController);

 

this would work if you were looking for a component on the SAME object

     var player : GameObject = GameObject.Find("NameOfPlayerObject");    
    var Facingscript : PlayerAnimationController = player.GetComponent(PlayerAnimationController);

 

this is more like what you need

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

13 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

Related Questions

Accessing a variable within a function.... GetComponent() 2 Answers

Variable from a external script not being effected 2 Answers

Running faster while flashlight is off 3 Answers

GetComponent with variable script possible? 1 Answer

Boolean not switching? 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