Everytime when i instantiate a object in this case a Turret, the script is attached but its not filled, i have a target field which needs a GameObject, but i have no clue how to attach the gameobject, in this case; FPSController…
i tried something like this;;
var myinstance = Instantiate(node, hitInfo.point, transform.rotation);
var script = GetComponent<Turret>();
But i have no idea how to proceed…
You can just call your “script” variable…
Assume you have this in your “Turret” script:
public float power = 10f;
You would then do something like this:
Turret script = GetComponent<Turret>() as Turret;
script.power = 20f;
Its c# ^-^, eh, well as i said, i need to add a gameobject to the script that is being instantiated
I am using this now;
if(hitInfo.collider.tag == "Enemy")
{
EnemyHealth script = GetComponent<EnemyHealth>() as EnemyHealth;
script.enemyHealth -= 100;
}
I get this error on clicking it:
Thats script.enemyHealth -= 100; that line
Fixed that, just getting back at the old thread