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 navigate the site we have posted a site navigation 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.
Answers and Comments
11 People are following this question.
I am trying to use a variable in the parameter of gameObject.GetComponent("var's Name").
Creating an ordered list from a variable
Passing a Variable to an Instance
Script reference from another c# script
Problem with 2 scripts communicating