How to activate gameobject based on enemy position

Hello,

I am after a bit of advice about how to handle something. I have a spider enemy that moves up and down in my game. I want to add a thread from the web to the spider which increases / decreases depending on whether they are moving up or down.

I have a sprite for the thread which is 16px tall. Just not sure how to make it increase. I am guessing I need multiple sprites and activate / deactivate them based on the spider position, but that seems like an awful lot of looping through a list for every frame. I don’t really want to just stretch the thread either using an animation because the spider can stop for a moment between waypoints and can also move at different speeds.

Any suggestions would be welcomed.

Many Thanks,

J

Not sure who else is going to do the work. Iterating a few dozen sprites isn’t gonna kill you.

Hi,

Thank you for your reply.

Ok, will loop through though. Just wondered if there were any more performant options :slight_smile:

Many Thanks,

J

Are you having a performance issue?

DO NOT OPTIMIZE CODE RANDOMLY… always start by using the profiler:

Window → Analysis → Profiler

https://discussions.unity.com/t/841163/2

Optimizing UnityEngine.UI setups:

https://discussions.unity.com/t/846847/2

You can do this in coroutine so it will not run every frame but you can specify when it will run e.g. everytime your spider move