x


How to get components

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

more ▼

asked Oct 21, 2012 at 03:15 AM

thenachotech1113 gravatar image

thenachotech1113
352 98 110 130

full explanation on unityGems.com

Oct 21, 2012 at 05:36 AM Fattie
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Try using SendMessage, its a lot easier and cleaner. Something like:

 var deployer: GameObject;
 
 function Update(){
 
 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.

more ▼

answered Oct 21, 2012 at 03:39 AM

Noah 1 gravatar image

Noah 1
1.2k 121 93 108

awesome thanks

Oct 21, 2012 at 01:41 PM thenachotech1113
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1372
x745
x228
x8

asked: Oct 21, 2012 at 03:15 AM

Seen: 760 times

Last Updated: Oct 21, 2012 at 01:41 PM