Created
October 2, 2013 06:14
-
-
Save Zenneth23/6789750 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Object A needed to ref from ObjectB, with Component C inside it. | |
//Component C's public float c need to be adjust to 20.0f when made | |
public class ObjectA: Monobehaviour | |
{ | |
void Awake() | |
{ | |
if(Instantiate_GameObject( "ObjectB", "C" )) | |
{ | |
C tempC = GameObject.Find("ObjectB").GetComponent<C>(); | |
tempC.c = 20.0f; | |
} | |
} | |
bool Instantiate_GameObject( string gameObjectName, string refComponentName ) | |
{ | |
//If the GameObject is not already there, make it | |
if(GameObject.Find(gameObjectName) == null) | |
{ | |
GameObject tempGameObject = new GameObject(gameObjectName); | |
} | |
//If the GameObject doesnot need Component, ignore | |
if( refComponentName == "" ) return false; | |
//If the GameObject doesnot have needed Component, attach it | |
GameObject refGameObject = GameObject.Find(gameObjectName); | |
if( refGameObject.GetComponent(refComponentName) == null ) | |
{ | |
refGameObject.AddComponent(refComponentName); | |
//Return True if it is making new Component, so that additional code can be made to modify newly made Component | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment