|
The title speeks for itself, i use
It's supposed to deactivate the AI script, when the object the script is attached to, is selected (Using raycast), the objektnamn is the variable containg the name of the currently selected object. Then, when a other object is selected, i want the AI script to activate again. Whats the problem here guys? Thanks in advance!
(comments are locked)
|
|
That looks a bit weird. Where do you execute this code? in And finally the most important question: What do you want to achieve? If you have new information edit your question and don't post an answer if it's not an answer to the question. You should at least include the function that contains this code snippet and what's the type of your " edit Anyways, I guess that will never come to an end. Just some hints:
Here's an example script that should be attached to the camera which do the selection stuff. Iv'e edited the question.
Mar 15 '11 at 11:02 PM
Tommy
You didn't tell what's the scripts name. Is that script above the AI script? Also there are some things that can't really work. You placed your AddComponent part in the script body. You really should use a designated function like Start() for such things. The code in the body get executed after OnEnable() but you set your
Mar 15 '11 at 11:26 PM
Bunny83
Edited again...
Mar 16 '11 at 01:48 PM
Tommy
The script works awesome, thank you! But still, the objects won't stop walking around (The AI scripts makes em' follow waypoints) when the AI script isn't enabled. That's why i used Destroy().
Mar 16 '11 at 02:53 PM
Tommy
(comments are locked)
|
Still get error: BCE0019: 'AI' is not a member of 'UnityEngine.GameObject'. on the line: if(!objektnamn.AI).
Mar 17 '11 at 01:10 PM
Tommy
I'm not quite sure why it is not working. try just AddComponent, not gameObject.AddComponent.
Mar 17 '11 at 07:06 PM
zmar0519
That won't solve the problem on line: if(!objektnamn.AI) unfortunately.
Mar 17 '11 at 08:36 PM
Tommy
(comments are locked)
|
|
your code is fine, but you are just missing an if statement. try this: It stills adds infinite number of the AI script :/
Mar 15 '11 at 08:31 PM
Tommy
Also, "objektnamn" is string, so i get error "Assets/Scripts/AI.js(37,20): BCE0019: 'AI' is not a member of 'String'.", on the line "if(!objektnamn.AI)".
Mar 15 '11 at 08:33 PM
Tommy
The reason that it does not work is because objektnamn is a string. Change it to a GameObject, and change else to else is(this.gameObject.name != objektnamn.name)
Mar 15 '11 at 08:43 PM
zmar0519
Sorry about the spelling error, else if(this.gameObject.name != objektnamn.name)
Mar 15 '11 at 08:44 PM
zmar0519
Thank you Joe, it's improving, almost there now i belive. Now the only problem is that, as soon as i run the game, the AI script get's destroyd. It's probably something really simple that iv'e should have seen. Here's the code: if (this.gameObject.name==objektnamn) { //GetComponent(AI).enabled = false; Destroy (GetComponent (AI)); } else if(this.gameObject.name != objektnamn.name) { gameObject.AddComponent (AI); }
Mar 15 '11 at 08:50 PM
Tommy
(comments are locked)
|
|
The code: Is that an answer to your question? If not you should edit your question and don't post comments as answers. Please read the FAQs. http://answers.unity3d.com/faq
Mar 15 '11 at 10:56 PM
Bunny83
(comments are locked)
|
