Search Unity

How to instantiate new player prefabs

Discussion in 'Scripting' started by tater_pie, Feb 11, 2019.

  1. tater_pie

    tater_pie

    Joined:
    Feb 11, 2019
    Posts:
    3
    I'm making a 2D game with unity, I'm an experienced Java programmer and decided to learn C#.
    My game is a 2D MMORPG and I'm writing the entire server by hand, and using 0 unity network management stuff, so my questions are:

    How do i (In code):
    instantiate and spawn a new player object into a scene
    manipulate that objects animations and position, etc on screen (i have information being fed from the server about all the players that are visible to this player)

    I really just need some snippets, I can figure out the logistics in between..

    I know theres like, Instantiate() method and such but not quite sure how to manipulate the animations and such, i have different prefabs for different types of characters so it may get complicated but thats ok
     
    Last edited: Feb 11, 2019
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    3,932
    Indeed ALL of these things possible to do in Unity. It is an enormous and wonderful playground, but you must do your own legwork to identify how to use each part.

    I recommend one step at a time, and all of the steps can be found here: Learn
     
    Munchy2007 likes this.
  3. tater_pie

    tater_pie

    Joined:
    Feb 11, 2019
    Posts:
    3
    im learning it one step at a time, i was looking for a formal explanation on how this would work in my current context not having access to monobehavior or another script.
    thanks for... the links to the tutorials i guess... i appreciate the effort
     
  4. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,218
    I don't understand what you mean by this, how can you not have access to Monobehaviour if you're using Unity, even if you are writing your own network code?

    Btw, I would have pointed you to the same tutorials as those that kurt-decker did.
     
    Kurt-Dekker likes this.
  5. tater_pie

    tater_pie

    Joined:
    Feb 11, 2019
    Posts:
    3
    my apologies for being rude I was mainly upset because i see people that know much less asking much dumber questions and people bend over backwards to answer them, but i asked a very straight forward question and get sent to the tutorials lol. And i was wrong i needed to have access to monobehavior.. i just hadn't figured it out yet
    I should have been more explanative before, I was mostly curious about iterating through my current animation from my animator object thats attached to my player prefab.. i have set up translation methods to translate my server code to animation indexes to raw animation sprite paths, for use with LCP universal character spritesheet...

    I figured out how to instantiate the players on my own, my real trouble(and trouble i was anticipating all along)
    is how to create an array of sprites from an animationclip object and then change it, and then set it within the animation clip, then cache it to save memory and so i can make selective changes to it here and there like equipping or unequipping a helmet for example

    My objective is to be able to have fully custom characters in my 2D game but i would have to create literally 500k prefabs to get the desired effect the way that unity is set up, rather then just editing the sprites of the animation while in memory and changing them as we cache the update block from the server.... i may not have gone into detail enough before i guess i can elaborate further if you need as well or post code
    Is this even possible?

    Explicity, if i could make 1 animation that has an alpha'd (blank) placeholder for all my possible appearance slots that would be ideal, and then just load and cache it on runetime..?

    theres this: https://forum.unity.com/threads/changing-sprites-in-animation.529009/

    that guy does something very similar but his animations and sprite layers are a lot less complex than mine:



    And I believe he created an actual animation file for each class, i want to have 1 prefab and 1 set of animations, that i can combine with other sprites along the way to make different combinations of characters
     
    Last edited: Feb 14, 2019