Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Projectile with target

Discussion in 'Multiplayer' started by xXApOXx, Jul 9, 2015.

  1. xXApOXx

    xXApOXx

    Joined:
    Feb 9, 2015
    Posts:
    76
    Hi guys,

    I'm developping a little game with a wizard that can launch fireballs on foes but when I try to assign a target to the spell, it only works on the host. The spell does appear on clients but stay at the initiale position.

    When I try to launch a spell from clients, it also appears on all applications but even in the client who is the launcher, the fireball doesn't move.

    I figured it out that in my command, the parameters Transform target, is null when it's from a client.

    I tried many things but still my fireball doesn't move.

    Here it's my last version of it :

    On my player I have a script that launch the spell when the player clic on a valide target, the update ends by that command
    Code (csharp):
    1. [Command]
    2. private void CmdSpawnSpell(Transform target)
    3. {
    4.     GameObject newSpell = (GameObject)Instantiate(Resources.Load<GameObject>("Spells/Test"), launcher.position, Quaternion.identity);
    5.     NetworkServer.Spawn(newSpell);
    6.  
    7.    newSpell.GetComponent<SpellMovements>().Target = target;
    8. }
    Then I have a Syncvar "target" on my SpellMovements script and if my target isn't null, the update should move the spell on the target.

    Thx for any solutions and sorry for my bad english !
     
    Last edited: Jul 9, 2015
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    Try passing the NetworkIdentity of the target instead of the Transform.
     
  3. xXApOXx

    xXApOXx

    Joined:
    Feb 9, 2015
    Posts:
    76
    Thx, I have a little improvement, now on the host, i see fireballs from every players move but still not in clients

    EDIT : When i log the target, it's still null on client
     
  4. xXApOXx

    xXApOXx

    Joined:
    Feb 9, 2015
    Posts:
    76
    Well I figured it out, so I post a reply in case someone have the same issue :

    In fact I tried to syncronize the variable from the launcher script but I had to do it on the script on the fireball itself. I don't know if there is an other better solution but it works that way.