/* * Section 5.3.2 Instancing */ private void Start() { PianoCat famousCat = new PianoCat(); /* * famousCat is now an instance of a PianoCat */ famousCat.PlayPiano(); // Meow from PianoCat famousCat.Meow(); // Meow from Cat Debug.Log(famousCat.paws); //paws from Cat }
// Use this for initialization void Start () { PianoCat famousCat = new PianoCat (); famousCat.PlayPiano (); famousCat.Meow (); print (famousCat.Paws); GameObject[] gos = GameObject.FindObjectsOfType (typeof(GameObject)) as GameObject[]; foreach (GameObject go in gos) { print (go); Component comp = go.GetComponent (typeof(Parent)); if(comp != null){ ChildObject = go; } } }
void UseIs() { Cat cat = new Cat(); PianoCat pianoCat = new PianoCat(); ComputerCat computerCat = new ComputerCat(); bool pianoCatIsCat = pianoCat is Cat; Debug.Log("PianoCat is a Cat?" + (pianoCatIsCat ? "True" : "False")); // PianoCat is a Cat? True bool pianoCatIsComputerCat = pianoCat is ComputerCat; Debug.Log("PianoCat is a ComputerCat?" + (pianoCatIsComputerCat ? "True" : "False")); // PianoCat is a ComputerCat False }
// As appears in 5.3.4 // Use this for initialization // void Start () // { // PianoCat famousCat = new PianoCat(); // famousCat.PlayPiano(); // famousCat.Meow(); // Debug.Log(famousCat.Paws); // GameObject[] gos = GameObject.FindObjectsOfType(typeof(GameObject)) as GameObject[]; // foreach (GameObject go in gos) // { // Debug.Log(go); // Component comp = go.GetComponent(typeof(Child)); // //it's mentioned but, we should iterate, if the // //comp isn't actually on the game object go, we // //are assigning null to comp! // } // } // As appears in 5.3.5 // Use this for initialization // void Start () // { // PianoCat famousCat = new PianoCat(); // famousCat.PlayPiano(); // famousCat.Meow(); // Debug.Log(famousCat.Paws); // GameObject[] gos = GameObject.FindObjectsOfType(typeof(GameObject)) as GameObject[]; // foreach (GameObject go in gos) // { // Debug.Log(go); // Component comp = go.GetComponent(typeof(Child)); // if( comp != null ) // { // ChildObject = go; // } // } // } //Use this for initialization void Start() { PianoCat famousCat = new PianoCat(); famousCat.PlayPiano(); famousCat.Meow(); Debug.Log(famousCat.Paws); GameObject[] gos = GameObject.FindObjectsOfType(typeof(GameObject)) as GameObject[]; GameObject[] obs = Object.FindObjectsOfType(typeof(GameObject)) as GameObject[]; foreach (GameObject go in gos) { Debug.Log(go); Component comp = go.GetComponent(typeof(Child)); if (comp != null) { ChildObject = go; } } }