- Home /
How to get a float from a parent object
A little of background may help. I have these units that are selectable, I want a quad with a texture to render when its parent unit is selected. "You should use a projector, a quad will glitch throught the ground" you may say, but the game is set in space, there's no ground. My plan was to set a float to 1 as long as the unit is selected, and 0 otherwize in the script that detects if the unit is selected. I can´t, however, access that variable from the scrip in the quad, therefore, I can't demonstrate the units are selected. How do I access those variables?
Answer by coinnip_unity · Aug 14, 2018 at 01:47 AM
// In parent script (this will be an unit.)
public float FloatValue {public get; private set;}
// In child script (this will be the (child) quad)
gameObject.GetComponentInParent</*Script Name that Include "FloatValue"*/>().FloatValue
// but i recommand you use bool or boolean instead of using float where just need 1 or 0
$$anonymous$$y plan was to multiply the quad dimensions by the float value, the float is called "indicatorSize". Anyway, I will tell if it worked once I get the parent script to work.
Thank you, I needed to change a little but it is getting the float. The code that was supposed to change the dimensions isn't working but I can confirm it gets the float correctly.