2
\$\begingroup\$

so, I want to make such functionality in my 2d game with unity :

Multi skin character, with similar control and functionality, and with possible different gimmicks (such as crossy road's characters, which some modify game environment and / or have unique death animation, yet THEY CAN ONLY JUMP AROUND a.k.a only cosmetic).

Here's so far what I did :

Make each character into separate gameobjects and prefabs, and then if I need to find a particular script in current active char, I use Gameobject.Find(). The problem is, if I need to apply a script, I need to > manually attach it 1 by 1 to each char gameobjects, which I find will create problems if the character number grows.

Is that a good practice? Or there's any more good / best practice on this problem?

P.S.

  1. I once read Gameobject.Find() is slow, so if possible, I want to avoid that.
  2. I use bone-based sprite animation, so, I think, changing just the Sprite in SpriteRenderer component won't work.

Thank you.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Basically you just change the sprites through code depending upon the skin type. You should not put the code in Late Update as shown in the tutorial as its just for demonstration purpose. Call the function only once when you want to update the skin.

You can find the complete tutorial in this link - https://youtu.be/HM17mAmLd7k?t=1609

And the entire source code for the tutorial in this link - http://goo.gl/6oSzDx

\$\endgroup\$
7
  • \$\begingroup\$ Hmm. I need to clarify something, how if I want to make "walk" animation? Is it by make "walk" animation on such controller, and then "pointing" each skin animation to that "walk" animation? If the answer is yes, then I think I got your point. \$\endgroup\$ Commented Oct 13, 2015 at 15:41
  • \$\begingroup\$ are you using sprite animation or unity animation with cut out parts?? \$\endgroup\$
    – Hash Buoy
    Commented Oct 13, 2015 at 15:50
  • \$\begingroup\$ Bone based / cut out part (as ive stated earlier in op) \$\endgroup\$ Commented Oct 13, 2015 at 15:51
  • \$\begingroup\$ ohh , wait ill update my answer \$\endgroup\$
    – Hash Buoy
    Commented Oct 13, 2015 at 15:52
  • \$\begingroup\$ Ah nice! Btw i need to try it first so, since I am now on trip, maybe i'll accept it next week after i come back. Thanks so much \$\endgroup\$ Commented Oct 13, 2015 at 16:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .