- Home /
Question by
AD110 · Apr 18, 2015 at 08:35 PM ·
gameobjectinstantiateprefab
Is it possible to disable/enable game-object inside Instantiate PreFab c#
So, here player1 and player2 are the clones, I just changed the name of the clones, I have disabled the meshRenderer of all my weapons, What I want to do is I want to enable sword in the first clone and bow in the second.
public void NameofCharacter(GameObject CharacterName, string name){
//This will assign a new name to the clone
CharacterName = m_gameObject;
CharacterName.name = name;
}
Vector3 PlayerPosition = m_gameObject.transform.position;
//if the position of the m_gameobject is equal to the given vector
if (PlayerPosition == new Vector3 (0, 0, 0)) {
//it will change the name of the clone
NameofCharacter (Player1,"Player 1");
GameObject Sword = GameObject.Find("Sword");
Sword.GetComponent<MeshRenderer>().enabled = true;
}
//if the position of the m_gameobject is equal to the given vector
if (PlayerPosition == new Vector3 (0, 0, 7)) {
//it will change the name of the clone
NameofCharacter (Player2,"Player 2");
GameObject Bow = FindObjectOfType<GameObject>();
Bow.GetComponent<MeshRenderer>().enabled = true;
}
screen-shot-2015-04-17-at-92815-pm.png
(13.2 kB)
Comment