Quantcast
Channel: Latest Questions by Griffo
Viewing all articles
Browse latest Browse all 94

OnBecameVisible() .. GetComponent(ScriptName)

$
0
0
Hi, I have a simple script (below) that I attach to EVERY enemy in the game to tell me if they are visible or not, the script is attached to each of the LOD renderer on each enemy. My problem is accessing the root script, as each different kind of enemy has a different named script, so I would like this script to be able to look at the root gameObject and find the script itself, but I'm sure theres no way of doing that without using GetComponent(ScriptName) .. Anyone know of a simple way of achieving this? Or have I got to put a copy of the script on every enemy with their script name in GetComponent? Thanks. #pragma strict private var mainScript : SoldierGunSWAT_01; // used for testing private var k : int; // ------------------------------------ function Start () { mainScript = transform.root.gameObject.GetComponent(SoldierGunSWAT_01); } // ------------------------------------ // Enables the behaviour when it is visible function OnBecameVisible() { // this yield need to be here else the OnBecameInvisible() // function below sets the variable to false as the other // LOD renderer on this model is swapped out yield WaitForSeconds(0); mainScript.soldierVisable = true; } // ------------------------------------ // Disables the behaviour when it is invisible function OnBecameInvisible () { mainScript.soldierVisable = false; } // ------------------------------------

Viewing all articles
Browse latest Browse all 94

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>