Hi folks,
I’m curious as to what would be more costly performance wise, and additionally, what would be a better method of implementation (if either): Passing a GameObject to one master “move” class that all objects can access – OR – Attaching a move script to every object that can move, passing no GameObject, and simply using attached gameObject.
An example of what I mean.
public class MoveThings : MonoBehaviour {
/*this script, attached to one "move manager" GameObject that all movable objects access*/
void DoMove(GameObject thingToMove)
{
if (thingToMove.tag == "Player")
thingToMove.transform.position = Lerp... //Player specific movement variables
if (thingToMove.tag == "Enemy")
thingToMove.transform.position = Lerp... //Enemy specific movement variables
}
}
//OR this script, attached to ALL things that can move.
class MoveThings: MonoBehaviour {
void DoMove()
{
if (gameObject.tag == "Player")
DoPlayerMove... //Using attached gameObject
if (gameObject.tag == "Enemy")
DoEnemyMove... //Using attached gameObject
if (gameObject.tag == "specialEnemy")
DoSpecialEnemyMove... //Using attached gameObject
}
}
Thanks! Apologies if this has been asked before. I tried searching a few things, but I wasn’t certain what I should even search.
Edit: I just realized I didn’t update my title appropriately. Changed it to fit my actual question better.