Write values on an instantiated Gameobject ?
Hey there !
I'm kind of new here, so to practice myself I'm trying to make a little tank-game.
Actually I have a tank class that can shoot like "bolts". When a tank shoot on an other, I would just like to be able to "write" the damage to make from the shooter tank to the bolt gameobject and then "read" these damage on contact with a tank.
But I don't know how to write these damage on the "bolts", I tried to instantiate in a "create" function what should allow me to use directly the gameobject (with gameobject XXX = instantiate [...] as gameobject) but I don't know why I can't access the values from that object instantiated.
A little bit of help ? Many thanks ! Enjoy you're week end !
Answer by Commoble · Feb 03, 2018 at 08:55 PM
This page in the unity manual has some sections on accessing and controlling other gameobjects the components/scripts on them
https://docs.unity3d.com/Manual/ControllingGameObjectsComponents.html
All right did not get that "GetComponent" could be used that way (was thinking it was only usable to read values, not to assign them)
Thanks !