Answers for "how to iterate through a game object in unity"

C#
0

how to iterate through a game object in unity

void FixedUpdate()

{
    GameObject objects = GameObject.FindGameObjectsWithTag("Enemy");
    var objectCount = objects.Length;
    foreach (var obj in objects)
    {
        // Move the players accordingly
        //var rb = 
        Vector2 direction = (player.position - transform.position).normalized;
        obj.rigidbody.velocity = direction * moveSpeed;

    }
}
Posted by: Guest on March-10-2021

Code answers related to "how to iterate through a game object in unity"

C# Answers by Framework

Browse Popular Code Answers by Language