hey, i need to get a component from a script that is supposed to deploy a turret when there is no turrets left, so i thought, for the script to know how many there are and when they die i need the get component to change variables, so i begun with the one just for it to count how many there are i tried this:
var deploy = Deployer.GetComponent(turret deploy).turretCount = turretCount + 1;
(deploy is the function to deploy it and Deployer is the object they will be deployed from)
im getting 2 errors, one tells me to put a semicolon right after GetComponent, and the other tells me the closing parenthesis its an unexpected token.
so any help is much appreciated, sorry for any spelling mistakes
full explanation on unityGems.com
Answer by Noah 1
Oct 21, 2012 at 03:39 AM
Try using SendMessage, its a lot easier and cleaner.
var deployer: GameObject;
deployer.SendMessage ("deployer", +1);
Then every script attached to the gameObject with the Deployer function will be called. Just create the function and inside it add your code to instantiate the turret when you run out of them.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users post good questions and use the site effectively we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
11 People are following this question.
Passing a Variable to an Instance
Find + GetComponent not working as expected
Implicit downcast from 'Object' to 'String'. GetComponent from another object
Problem with 2 scripts communicating
When editing a scripts variable in another script, does the original script update?