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 ManiacalSquare · Apr 04, 2012 at 10:00 AM · variableinstanceaccessing

Accessing variable of script on an instance.

 var chutist : GameObject;
 var chutistClone : GameObject;
 
 function Start () {
 
     chutistClone = Instantiate(chutist, Vector3(transform.position.x,transform.position.y -0.85, transform.position.z),transform.rotation);
 
 }
 
 
 function OnTriggerEnter(Col : Collider){
  
  if (Col.gameObject.tag == "Bullet"){
      
      life -= 10;
  }
  
  if (life == 0){
      
      chutistClone.rigidbody.drag = 0;
      chutistClone.GetComponent(chutist).drop = true;
      yield WaitForSeconds (0.01);
      destruct();
  }



This is about the part "chutistClone.GetComponent(chutist).drop = true;"

I've checked out various methods of accessing scripts on other objects, But I can't figure out why this does not work. Unity gives me:

BCE0023: No appropriate version of 'UnityEngine.GameObject.GetComponent' for the argument list '(UnityEngine.GameObject)' was found.

If I change (chutist) to ("chutist") it gives me:

BCE0019: 'drop' is not a member of 'UnityEngine.Component'.


What am I missing? What am I doing wrong?

Thanks in advance, Bor.

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 ManiacalSquare · Apr 04, 2012 at 10:28 AM 0
Share

PS. I specifically do NOT want to use a static variable. Hence this method.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Statement · Apr 04, 2012 at 10:34 AM

The problem is that you are sending a game object into a function that expect a type.

 var chutist : GameObject;
 ...
 chutistClone.GetComponent(chutist).drop = true;

I would assume you meant to do something similar to this:

 chutistClone.GetComponent.<ChutistScript>().drop = true;

But I don't know the type of the component you are trying to access.
Change ChutistScript to the type of component that has the drop variable.

If you get a null reference exception after you do this, it likely means that you don't have the script on the object you cloned.

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 ManiacalSquare · Apr 04, 2012 at 12:20 PM 0
Share

I was really stupid. Everything was fine, except the variable "chutist " was named the same as the script "chutist". So it was trying to access the wrong thing. Changed the variable name to chutist1, everything is working fine now. Sorry for wasting your time guys. Thanks to your answer I figured it out. So TYV$$anonymous$$!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Updating variable on another script. It is not working. 2 Answers

accessing a variable from another script. 3 Answers

Problem with accessing variable form other scripts. 1 Answer

Is it possible to change a variable, into a script not assigned to any game object? 3 Answers

Can't understand generic getComponent for Js 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