void Update()
{
goTopToDown();
}
void goTopToDown()
{
//transform.position += Vector3.down * speed * Time.deltaTime;
//find with tag and move top to down object ex: 8 object should be slow move top to down
if(gameObject.tag== "obstacleobject")
{
transform.position += Vector3.down * speed * Time.deltaTime;
Debug.Log("GameObject Name:" + gameObject.tag);
Debug.Log("inside vertical object");
}
//find with tag and Vertical Rotate object //ex: 1 game object should be rotate left to right
if (gameObject.tag == "verticalrotateobject")
{
transform.Rotate(Vector3.forward, turnSpeed * rotatesped * Time.deltaTime);
transform.position += Vector3.down * speed * Time.deltaTime; //move top to down
Debug.Log("GameObject Name:" + gameObject.tag);
Debug.Log("inside vertical object");
}
//find with tag and move fast object ex: 2 object is speed is very fast
if (gameObject.tag == "movefastobject")
{
transform.position += Vector3.down * movefastobjectspeed * Time.deltaTime
Debug.Log("GameObject Name:" + gameObject.tag);
Debug.Log("inside movefast object");
}
}
void OnTriggerEnter2D(Collider2D other) // i want to when three tag gameobject collided with my player then trigger fire
{
foreach (Transform child in transform)
{
if (child.tag == "obstacleobject" || child.tag == "movefastobject" || child.tag == "verticalrotateobject")
{
Debug.Log("chiildtag:" + child.tag);
gameovertext.SetActive(true);
StartCoroutine(gameover());
Debug.Log("inside triggerfire");
}
}
You are just checking if the parent object has the tag. Instead, you need to cycle through all the parents children and see if they have the tag. Something like this:
–
private void goTopToDown()
{
foreach(Transform trans in transform)
{
if (trans.tag == "obstacleobject")
{
}
else if (trans.tag == "verticalrotateobject")
{
}
else if (trans.tag == "movefastobject")
{
}
}
}
void Update()
{
goTopToDown();
}
void goTopToDown()
{
//transform.position += Vector3.down * speed * Time.deltaTime;
//find with tag and move top to down object ex: 8 object should be slow move top to down
foreach (GameObject item in GetComponentsInChildren<GameObject>())
{
if (item.tag == "obstacleobject")
{
transform.position += Vector3.down * speed * Time.deltaTime;
Debug.Log("GameObject Name:" + gameObject.tag);
Debug.Log("inside vertical object");
}
//find with tag and Vertical Rotate object //ex: 1 game object should be rotate left to right
if (item.tag == "verticalrotateobject")
{
transform.Rotate(Vector3.forward, turnSpeed * rotatesped * Time.deltaTime);
transform.position += Vector3.down * speed * Time.deltaTime; //move top to down
Debug.Log("GameObject Name:" + gameObject.tag);
Debug.Log("inside vertical object");
}
//find with tag and move fast object ex: 2 object is speed is very fast
if (item.tag == "movefastobject")
{
transform.position += Vector3.down * movefastobjectspeed * Time.deltaTime
Debug.Log("GameObject Name:" + gameObject.tag);
Debug.Log("inside movefast object");
}
}
}
void OnTriggerEnter2D(Collider2D other) // i want to when three tag gameobject collided with my player then trigger fire
{
foreach (Transform child in GetComponentsInChildren<Transform>())
{
if (child.tag == "obstacleobject" || child.tag == "movefastobject" || child.tag == "verticalrotateobject")
{
Debug.Log("chiildtag:" + child.tag);
gameovertext.SetActive(true);
StartCoroutine(gameover());
Debug.Log("inside triggerfire");
}
}
}
void Update()
{
goTopToDown();
}
void goTopToDown()
{
//transform.position += Vector3.down * speed * Time.deltaTime;
//find with tag and move top to down object ex: 8 object should be slow move top to down
foreach (Transform item in GetComponentsInChildren<Transform>())
{
if (item.tag == "obstacleobject")
{
transform.position += Vector3.down * speed * Time.deltaTime;
Debug.Log("GameObject Name:" + gameObject.tag);
Debug.Log("inside vertical object");
}
//find with tag and Vertical Rotate object //ex: 1 game object should be rotate left to right
if (item.tag == "verticalrotateobject")
{
transform.Rotate(Vector3.forward, turnSpeed * rotatesped * Time.deltaTime);
transform.position += Vector3.down * speed * Time.deltaTime; //move top to down
Debug.Log("GameObject Name:" + gameObject.tag);
Debug.Log("inside vertical object");
}
//find with tag and move fast object ex: 2 object is speed is very fast
if (item.tag == "movefastobject")
{
transform.position += Vector3.down * movefastobjectspeed * Time.deltaTime
Debug.Log("GameObject Name:" + gameObject.tag);
Debug.Log("inside movefast object");
}
}
}
void OnTriggerEnter2D(Collider2D other) // i want to when three tag gameobject collided with my player then trigger fire
{
foreach (Transform child in GetComponentsInChildren<Transform>())
{
if (child.tag == "obstacleobject" || child.tag == "movefastobject" || child.tag == "verticalrotateobject")
{
Debug.Log("chiildtag:" + child.tag);
gameovertext.SetActive(true);
StartCoroutine(gameover());
Debug.Log("inside triggerfire");
}
}
}