Search Unity

How to improve an action made on sevral objects

Discussion in 'Scripting' started by Ekivenum, Dec 24, 2018.

  1. Ekivenum

    Ekivenum

    Joined:
    Jan 16, 2018
    Posts:
    8
    Hello world!

    I wonder was is more efficient in performance for what i want to do,

    I have 100 objects, they represents placement areas for a tower to fit in it. When the player selects a tower i want those PA(placement area) to change scale and Material, back and forth from original to a specific scale and material, until the player choose a PA or cancel it. Also, the PA will only do this if there is no tower on it.

    n.b: on a pas there is: -a script that reference two materials they use to set on a quad, one filled(tower is on it) other when the PA is tower free. it also got a ref from the mesh(quad) -Mesh renderer -Quand (Mesh Filter )

    To do this i think i will create an animator controller with two animations, idle and inMotion. I will add a the script 1 methode for trigger the inMotion/idle animation regarding if the player's selecteTowerToBuild variable is null or not. This methode will subscrib to the event "selectedTowerChange" on the start methode and will unsubscrib on disable/destroy and also if the the PA statu goes to filed by a tower.

    Now questions: Is it better to add all the PA in a list and PA will remove it sell when filed. Then trigger an the "selectedTowerChange" event and check if the towerToBuild variable != null to iterate all the list asking the PA to trigger idle or inMotion aniamation? here i don't have all PA responding to the event, but only one methode How to add the changing the material in my animations? (not a problem if i go with the list)

    I think animation solution is better than a coroutine that iterate thouth all PA but is it better than update with iteration or any other way? do you have a better way and could explain in what it is better.

    Thank you