- Home /
Question by
Resilo · May 24, 2017 at 07:41 AM ·
physicsnetworkingtriggerserverauthoritative
ontriggerenter will not work with !islocalplayyer
So after struggling with this for a long time i am hoping someone has an answer to this. i am using the OnTriggerEnter to allow damage to happen if i put !islocalplayer{return;} then it happens on no ones client
if i dont put !islocalplayer{return;} then the server can only execute the code.
so i need to know what edits i can make to allow this to be executed only on the local player
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class Gettindamaged : NetworkBehaviour
{
public GameObject player;
public bool candamage;
public GameObject targeting;
public GameObject enemy;
public bool noshield;
public Animator anim;
public Animator playeranim;
void OnTriggerEnter(Collider other)
{
if (other != this.gameObject && other != player)
{
Debug.Log(player);
}
if (isLocalPlayer)
{
enemy = other.gameObject;
anim = other.gameObject.GetComponent<Animator>();
if (candamage == true && other.gameObject.tag.Contains("Enemy") && noshield == false)
{
Debug.Log("damage");
Debug.Log(other.gameObject);
//defemce
if (candamage == true && player.GetComponent<Attackdirection>().attacknumber == other.gameObject.GetComponent<AIattackdirection>().attacknumber && other.GetComponent<Stats>().sword.GetComponent<AIdoesdamage>().noshield == false)
{
Debug.Log("defence");
if (player.GetComponent<Attackdirection>().attackingleft == true && other.gameObject.GetComponent<AIattackdirection>().attackingleft == true)
{
anim.SetTrigger("blockedleft");
playeranim.SetTrigger("parriedleft");
other.GetComponent<Stats>().shield.GetComponent<Stats>().takingdamage(1);
}
if (player.GetComponent<Attackdirection>().attackingup == true && other.gameObject.GetComponent<AIattackdirection>().attackingup == true)
{
anim.SetTrigger("blockedup");
playeranim.SetTrigger("parriedup");
other.GetComponent<Stats>().shield.GetComponent<Stats>().takingdamage(1);
}
if (player.GetComponent<Attackdirection>().attackingright == true && other.gameObject.GetComponent<AIattackdirection>().attackingright == true)
{
anim.SetTrigger("blockright");
playeranim.SetTrigger("parriedright");
other.GetComponent<Stats>().shield.GetComponent<Stats>().takingdamage(1);
}
if (player.GetComponent<Attackdirection>().attackingdown == true && other.gameObject.GetComponent<AIattackdirection>().attackingdown == true)
{
anim.SetTrigger("blockedown");
playeranim.SetTrigger("parrieddown");
other.GetComponent<Stats>().shield.GetComponent<Stats>().takingdamage(1);
}
}
//attack
if (candamage == true && player.GetComponent<Attackdirection>().attacknumber != other.gameObject.GetComponent<AIattackdirection>().attacknumber || other.GetComponent<Stats>().sword.GetComponent<AIdoesdamage>().noshield == true && candamage == true)
{
Debug.Log("attack");
if (player.GetComponent<Attackdirection>().attackingleft == true && other.gameObject.GetComponent<AIattackdirection>().attackingleft == false || other.GetComponent<Stats>().sword.GetComponent<AIdoesdamage>().noshield == true)
{
Cmd_dodamage();
}
if (player.GetComponent<Attackdirection>().attackingup == true && other.gameObject.GetComponent<AIattackdirection>().attackingup == false || other.GetComponent<Stats>().sword.GetComponent<AIdoesdamage>().noshield == true)
{
Cmd_dodamage();
}
if (player.GetComponent<Attackdirection>().attackingright == true && other.gameObject.GetComponent<AIattackdirection>().attackingright == false || other.GetComponent<Stats>().sword.GetComponent<AIdoesdamage>().noshield == true)
{
Cmd_dodamage();
}
if (player.GetComponent<Attackdirection>().attackingdown == true && other.gameObject.GetComponent<AIattackdirection>().attackingdown == false || other.GetComponent<Stats>().sword.GetComponent<AIdoesdamage>().noshield == true)
{
Cmd_dodamage();
}
}
candamage = false;
}
//player
if (candamage == true && other.gameObject.tag.Contains("player") && other.gameObject != player.gameObject && other.GetComponent<Stats>().sword.GetComponent<Gettindamaged>().noshield == false)
{
Debug.Log("damag1e");
if (candamage == true && player.GetComponent<Attackdirection>().attacknumber == other.gameObject.GetComponent<Attackdirection>().attacknumber)
{
if (player.GetComponent<Attackdirection>().attackingleft == true && other.gameObject.GetComponent<Attackdirection>().attackingleft == true)
{
anim.SetTrigger("blockedleft");
playeranim.SetTrigger("parriedleft");
other.GetComponent<Stats>().shield.GetComponent<Stats>().takingdamage(1);
}
if (player.GetComponent<Attackdirection>().attackingup == true && other.gameObject.GetComponent<Attackdirection>().attackingup == true)
{
anim.SetTrigger("blockedup");
playeranim.SetTrigger("parriedup");
other.GetComponent<Stats>().shield.GetComponent<Stats>().takingdamage(1);
}
if (player.GetComponent<Attackdirection>().attackingright == true && other.gameObject.GetComponent<Attackdirection>().attackingright == true)
{
anim.SetTrigger("blockedright");
playeranim.SetTrigger("parriedright");
other.GetComponent<Stats>().shield.GetComponent<Stats>().takingdamage(1);
}
if (player.GetComponent<Attackdirection>().attackingdown == true && other.GetComponent<Attackdirection>().attackingdown == true)
{
anim.SetTrigger("blockeddown");
playeranim.SetTrigger("parrieddown");
other.GetComponent<Stats>().shield.GetComponent<Stats>().takingdamage(1);
}
}
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)
{
if (player.GetComponent<Attackdirection>().attackingleft == true && other.gameObject.GetComponent<Attackdirection>().attackingleft == false)
{
Cmd_dodamage();
}
if (player.GetComponent<Attackdirection>().attackingup == true && other.gameObject.GetComponent<Attackdirection>().attackingup == false || other.GetComponent<Stats>().sword.GetComponent<Gettindamaged>().noshield == true)
{
Cmd_dodamage();
}
if (player.GetComponent<Attackdirection>().attackingright == true && other.gameObject.GetComponent<Attackdirection>().attackingright == false || other.GetComponent<Stats>().sword.GetComponent<Gettindamaged>().noshield == true)
{
Cmd_dodamage();
}
if (player.GetComponent<Attackdirection>().attackingdown == true && other.gameObject.GetComponent<Attackdirection>().attackingdown == false || other.GetComponent<Stats>().sword.GetComponent<Gettindamaged>().noshield == true)
{
Cmd_dodamage();
}
}
candamage = false;
}
}
}
[Command]
void Cmd_dodamage()
{
enemy.gameObject.GetComponent<Stats>().takingdamage(player.GetComponent<Stats>().damage);
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
Comment
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Reliable physics across a network? 2 Answers
Authoritative vs Non-authoritative server (turn-based) 0 Answers
Authoritative server strategy 0 Answers
Can a person be both a client and a server? (and more) 0 Answers