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 Valdemars Magone · Feb 25, 2011 at 03:41 PM · iosfunctioncallbce0019

add is not a member of UnityEngine.Component

I know many of members have asked this question, I have tried to apply their solutions but they are not working for me. I have an object with this script :

function OnCollisionEnter (col : Collision) { if (col. gameObject.name == "Player"){ var go = GameObject.Find("Player"); go.GetComponent(testToAdd).add(); print("You have the key"); Destroy(gameObject); }

}

When Player hits the object, object gets destroyed and calls a function "add" in script "testToAdd.js", whitch is attached to Player. I'm using Unity 3.2 Pro Trial and try to build game on iPad, when receive the error from topic...

Comment
Add comment · Show 2
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 Statement · Feb 28, 2011 at 01:27 PM 0
Share

Is the add function public or private?

avatar image Valdemars Magone · Mar 01, 2011 at 08:22 PM 0
Share

Script containing add function looks like this :

function add () { gameObject.AddComponent("playerCollisionForDoor"); }

5 Replies

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

Answer by Valdemars Magone · Feb 28, 2011 at 12:24 PM

I found another solution, I attached this script to Player and changed it :

function OnCollisionEnter (col : Collision) { if (col. gameObject.name == "key"){

gameObject.AddComponent("playerCollisionForDoor"); print("You have the key"); // Destroy(gameObject); }

}

Before that this script was attached to gameObject Key...

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
avatar image
0

Answer by DaveA · Feb 25, 2011 at 04:03 PM

Try this:

var test2add : testToAdd = go.GetComponent(testToAdd);
test2add.add();
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 Valdemars Magone · Feb 28, 2011 at 08:52 AM 0
Share

Error : $$anonymous$$ identifier 'go'.

avatar image DaveA · Feb 28, 2011 at 06:23 PM 0
Share

You defined go in the line above

avatar image
0

Answer by efge · Feb 25, 2011 at 04:03 PM

I think it is better to declare variables:

var playerScript : testToAdd;
playerScript = go.GetComponent(testToAdd);
playerScript.add();


Better (but untested): use the information you get from collision, GameObject.Find is not necessary:

function OnCollisionEnter (col : Collision) {
  if (col.gameObject.name == "Player"){
    var playerScript : testToAdd;
    playerScript = col.gameObject.GetComponent(testToAdd);
    playerScript.add();col.gameObject.GetComponent(testToAdd).add();
    print("You have the key"); 
    Destroy(gameObject); 
 }
}
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 Valdemars Magone · Feb 28, 2011 at 08:49 AM 0
Share

Anyway I receive error : 'add' is not a member of UnityEngine.Component.

avatar image
0

Answer by Eric5h5 · Feb 25, 2011 at 05:20 PM

Use generics; also there's no reason to use GameObject.Find here since you already have a reference to that game object:

function OnCollisionEnter (col : Collision) {
 if (col.gameObject.name == "Player") {
  col.GetComponent.<testToAdd>().add();
  print("You have the key"); 
  Destroy(gameObject); 
 }
}
Comment
Add comment · Show 3 · 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 Valdemars Magone · Feb 28, 2011 at 08:51 AM 0
Share

Error: "'GetComponent' is not a memberof UnityEngine.Collision. Did you mean 'gameObject'?"

avatar image Statement · Feb 28, 2011 at 01:26 PM 0
Share

col.gameObject.GetComponent.().add() he probably means.

avatar image Eric5h5 · Feb 28, 2011 at 02:54 PM 0
Share

Indeed that's what I meant.

avatar image
0

Answer by Hei · Feb 27, 2011 at 12:48 AM

You find object script in Start ().

var playerObject : GameObject; var testToAddScript : testToAdd;

function Start () { testToAddScript = playerObject.gameObject.GetComponent("testToAdd"); }

function OnCollisionEnter (col : Collision) { if (col.gameObject.name == "Player") { print("You have the key"); Destroy(gameObject); } }

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

Calling Function in other Script via Touch => iOS Crash 1 Answer

What is the best way to call a function from another script 1 Answer

Have problem using Application.OpenURL() opening tel URL scheme on iOS to call a number with symbols 1 Answer

Call function after script compilation? 2 Answers

How to check if a function is called? 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