Question by
Dirga-Naratama · Aug 17, 2018 at 08:18 AM ·
c#programmingcodepage
How to communicate between scripts and gameobject use tag in unity
Hi Guyss... iam newbie here and i have a question here, can i communucate 2 GameObject and Script by tag?
for example :
1 Cube (Player)
5 Cube (Enemys)
in Player Cube, i put Movement Script and for Enemys Cube, i put Movement Script too. But, when player cube detect collision with enemys cube, i want 5 enemys cube disable the Movement Script.
for disable movement script in enemys cube, i make one script and i call it Player_Collusion and i put this script in player cube, in this script i will controll all enemys Movement script.
Hope you guys will understand what i mean. Iam sorry for Bad Grammar ^^
Thanks
Comment
Best Answer
Answer by jet-pack · Aug 17, 2018 at 08:24 AM
Player_Collision:
private void OnCollisionEnter(Collision collision)
{
if (collision.transform.tag == "Enemy")
{
collision.transform.GetComponent<MovementScript>().enabled = false;
}
}