Search Unity

cant force other playrs to perform animation

Discussion in 'Multiplayer' started by Resilo, May 19, 2017.

  1. Resilo

    Resilo

    Joined:
    Dec 8, 2016
    Posts:
    139
    So the main problem with this script is its suppose to force the object the sword hits to perform various animations but of course nothing happens instead. what edits do i need to force the object the sword hits to properly perform the animation?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5.  
    6. public class Gettindamaged : NetworkBehaviour
    7. {
    8.     public GameObject player;
    9.     [SyncVar]
    10.     public bool candamage;
    11.     public GameObject targeting;
    12.     [SyncVar]
    13.     public bool noshield;
    14.     public Animator anim;
    15.  
    16.  
    17.     void OnTriggerEnter(Collider other)
    18.  
    19.     {
    20.         anim = other.gameObject.GetComponent<Animator>();
    21.         if (!isLocalPlayer)
    22.             return;
    23.  
    24.         if (candamage == true && other.gameObject.tag.Contains("Enemy") && noshield == false)
    25.         {
    26.             Debug.Log(other.gameObject);
    27.             //defemce
    28.             if (candamage == true && player.GetComponent<Attackdirection>().attacknumber == other.gameObject.GetComponent<AIattackdirection>().attacknumber && other.GetComponent<Stats>().sword.GetComponent<AIdoesdamage>().noshield == false)
    29.             {
    30.                 Debug.Log("defence");
    31.                 if (player.GetComponent<Attackdirection>().attackingleft == true && other.gameObject.GetComponent<AIattackdirection>().attackingleft == true)
    32.                 {
    33.  
    34.                     Cmd_Animatenemy("blockedleft");
    35.                     Cmd_Animate("parriedleft");
    36.                     other.GetComponent<Stats>().shield.GetComponent<Stats>().takingdamage(1);
    37.  
    38.                 }
    39.                 if (player.GetComponent<Attackdirection>().attackingup == true && other.gameObject.GetComponent<AIattackdirection>().attackingup == true)
    40.                 {
    41.                     Cmd_Animatenemy("blockedup");
    42.                     Cmd_Animate("parriedup");
    43.                     other.GetComponent<Stats>().shield.GetComponent<Stats>().takingdamage(1);
    44.  
    45.  
    46.                 }
    47.                 if (player.GetComponent<Attackdirection>().attackingright == true && other.gameObject.GetComponent<AIattackdirection>().attackingright == true)
    48.                 {
    49.                     Cmd_Animatenemy("blockedright");
    50.                     Cmd_Animate("parriedright");
    51.                     other.GetComponent<Stats>().shield.GetComponent<Stats>().takingdamage(1);
    52.  
    53.  
    54.                 }
    55.                 if (player.GetComponent<Attackdirection>().attackingdown == true && other.gameObject.GetComponent<AIattackdirection>().attackingdown == true)
    56.                 {
    57.                     Cmd_Animatenemy("blockeddown");
    58.                     Cmd_Animate("parrieddown");
    59.                     other.GetComponent<Stats>().shield.GetComponent<Stats>().takingdamage(1);
    60.  
    61.  
    62.                 }
    63.  
    64.                
    65.             }
    66.  
    67.  
    68.  
    69.             //attack
    70.             if (candamage == true && player.GetComponent<Attackdirection>().attacknumber != other.gameObject.GetComponent<AIattackdirection>().attacknumber || other.GetComponent<Stats>().sword.GetComponent<AIdoesdamage>().noshield == true && candamage == true)
    71.             {
    72.                 Debug.Log("attack");
    73.                 if (player.GetComponent<Attackdirection>().attackingleft == true && other.gameObject.GetComponent<AIattackdirection>().attackingleft == false || other.GetComponent<Stats>().sword.GetComponent<AIdoesdamage>().noshield == true)
    74.                 {
    75.                     Cmd_Animatenemy("gethit");
    76.                     other.gameObject.GetComponent<Stats>().takingdamage(player.GetComponent<Stats>().damage);
    77.  
    78.  
    79.                 }
    80.                 if (player.GetComponent<Attackdirection>().attackingup == true && other.gameObject.GetComponent<AIattackdirection>().attackingup == false || other.GetComponent<Stats>().sword.GetComponent<AIdoesdamage>().noshield == true)
    81.                 {
    82.                     Cmd_Animatenemy("gethit");
    83.                     other.gameObject.GetComponent<Stats>().takingdamage(player.GetComponent<Stats>().damage);
    84.  
    85.                 }
    86.                 if (player.GetComponent<Attackdirection>().attackingright == true && other.gameObject.GetComponent<AIattackdirection>().attackingright == false || other.GetComponent<Stats>().sword.GetComponent<AIdoesdamage>().noshield == true)
    87.                 {
    88.                     Cmd_Animatenemy("gethit");
    89.                     other.gameObject.GetComponent<Stats>().takingdamage(player.GetComponent<Stats>().damage);
    90.  
    91.                 }
    92.                 if (player.GetComponent<Attackdirection>().attackingdown == true && other.gameObject.GetComponent<AIattackdirection>().attackingdown == false || other.GetComponent<Stats>().sword.GetComponent<AIdoesdamage>().noshield == true)
    93.                 {
    94.                     Cmd_Animatenemy("gethit");
    95.                     other.gameObject.GetComponent<Stats>().takingdamage(player.GetComponent<Stats>().damage);
    96.  
    97.                 }
    98.             }
    99.  
    100.                 candamage = false;
    101.         }
    102.  
    103.  
    104.  
    105.  
    106.  
    107.  
    108.         //player
    109.         if (candamage == true && other.gameObject.tag.Contains("player") && other.gameObject != player.gameObject && other.GetComponent<Stats>().sword.GetComponent<Gettindamaged>().noshield == false)
    110.         {
    111.  
    112.             if (candamage == true && player.GetComponent<Attackdirection>().attacknumber == other.gameObject.GetComponent<Attackdirection>().attacknumber)
    113.             {
    114.  
    115.                 if (player.GetComponent<Attackdirection>().attackingleft == true && other.gameObject.GetComponent<Attackdirection>().attackingleft == true)
    116.                 {
    117.                     Cmd_Animatenemy("blockedleft");
    118.                     Cmd_Animate("parriedleft");
    119.                     other.GetComponent<Stats>().shield.GetComponent<Stats>().takingdamage(1);
    120.  
    121.                 }
    122.                 if (player.GetComponent<Attackdirection>().attackingup == true && other.gameObject.GetComponent<Attackdirection>().attackingup == true)
    123.                 {
    124.                     Cmd_Animatenemy("blockedup");
    125.                     Cmd_Animate("parriedup");
    126.                     other.GetComponent<Stats>().shield.GetComponent<Stats>().takingdamage(1);
    127.  
    128.  
    129.                 }
    130.                 if (player.GetComponent<Attackdirection>().attackingright == true && other.gameObject.GetComponent<Attackdirection>().attackingright == true)
    131.                 {
    132.                     Cmd_Animatenemy("blockedright");
    133.                     Cmd_Animate("parriedright");
    134.                     other.GetComponent<Stats>().shield.GetComponent<Stats>().takingdamage(1);
    135.  
    136.  
    137.                 }
    138.                 if (player.GetComponent<Attackdirection>().attackingdown == true && other.GetComponent<Attackdirection>().attackingdown == true)
    139.                 {
    140.                     Cmd_Animatenemy("blockeddown");
    141.                     Cmd_Animate("parrieddown");
    142.                     other.GetComponent<Stats>().shield.GetComponent<Stats>().takingdamage(1);
    143.  
    144.  
    145.                 }
    146.             }
    147.  
    148.  
    149.             if (candamage == true && player.GetComponent<Attackdirection>().attacknumber != other.gameObject.GetComponent<Attackdirection>().attacknumber && other != player.gameObject || other.GetComponent<Stats>().sword.GetComponent<Gettindamaged>().noshield == true && candamage == true && other != player.gameObject)
    150.             {
    151.                 if (player.GetComponent<Attackdirection>().attackingleft == true && other.gameObject.GetComponent<Attackdirection>().attackingleft == false)
    152.                 {
    153.                     Cmd_Animatenemy("gethit");
    154.                     other.gameObject.GetComponent<Stats>().takingdamage(player.GetComponent<Stats>().damage);
    155.  
    156.  
    157.                 }
    158.                 if (player.GetComponent<Attackdirection>().attackingup == true && other.gameObject.GetComponent<Attackdirection>().attackingup == false || other.GetComponent<Stats>().sword.GetComponent<Gettindamaged>().noshield == true)
    159.                 {
    160.                     Cmd_Animatenemy("gethit");
    161.                     other.gameObject.GetComponent<Stats>().takingdamage(player.GetComponent<Stats>().damage);
    162.  
    163.                 }
    164.                 if (player.GetComponent<Attackdirection>().attackingright == true && other.gameObject.GetComponent<Attackdirection>().attackingright == false || other.GetComponent<Stats>().sword.GetComponent<Gettindamaged>().noshield == true)
    165.                 {
    166.                     Cmd_Animatenemy("gethit");
    167.                     other.gameObject.GetComponent<Stats>().takingdamage(player.GetComponent<Stats>().damage);
    168.  
    169.                 }
    170.                 if (player.GetComponent<Attackdirection>().attackingdown == true && other.gameObject.GetComponent<Attackdirection>().attackingdown == false || other.GetComponent<Stats>().sword.GetComponent<Gettindamaged>().noshield == true)
    171.                 {
    172.                     Cmd_Animatenemy("gethit");
    173.                     other.gameObject.GetComponent<Stats>().takingdamage(player.GetComponent<Stats>().damage);
    174.  
    175.                 }
    176.             }
    177.  
    178.             candamage = false;
    179.         }
    180.     }
    181.  
    182.  
    183.  
    184.  
    185.     [Command]
    186.     void Cmd_Animate(string trigger)
    187.     {
    188.         Rpc_Animate(trigger);
    189.     }
    190.  
    191.     [ClientRpc]
    192.     void Rpc_Animate(string trigger)
    193.     {
    194.         player.GetComponent<Animator>().SetTrigger(trigger);
    195.     }
    196.  
    197.  
    198.  
    199.     [Command]
    200.     void Cmd_Animatenemy(string trigger)
    201.     {
    202.         Rpc_Animateenemy(trigger);
    203.     }
    204.  
    205.     [ClientRpc]
    206.     void Rpc_Animateenemy(string trigger)
    207.     {
    208.         anim.SetTrigger(trigger);
    209.     }
    210.  
    211.  
    212.  
    213.     // Use this for initialization
    214.     void Start () {
    215.  
    216.     }
    217.    
    218.     // Update is called once per frame
    219.     void Update () {
    220.        
    221.     }
    222. }
    223.  
     
  2. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,243
    Hmm. Might be a dumb question but
    where do Cmd_Animatenemy and Rpc_Animateenemy methods get pointer to enemy in question?
    Or his animator, for that matter?
     
  3. Resilo

    Resilo

    Joined:
    Dec 8, 2016
    Posts:
    139
    anim = other.gameObject.GetComponent<Animator>();


    its at the beginning of void OnTriggerEnter(Collider other)
     
    FMark92 likes this.