What is the main problem with this loop?
for (int i=0;i<1000;i++) GetComponent<Rigidbody>();
- Repeated component lookups are costly
- Rigidbody cannot be fetched twice
- The loop never actually terminates
- GetComponent returns a new object
Cache the reference once instead of calling GetComponent every iteration.
Play Game Dev ▸