This targeting script worked perfectly before including networking
the character prefab has a child of the the player prefab with a collider as a trigger. now the issue is even though i have issued this gameobject a network idenitiy when i hit “Z” it does not even attempt to fire the code.
is it because i have more than 1 object with a local player authority or is it some other issue?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using UnityEngine.Networking;
public class Targeting : NetworkBehaviour {
public static List<GameObject> attackers = new List<GameObject>();
public Text targeting;
public int howmanyplayers;
public GameObject playertarget;
public Camera main;
public bool cameraturnon;
public bool lookattarget;
public Animator anim;
public GameObject player;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag.Contains("Enemy") || other.tag.Contains("player"))
{
if (!attackers.Contains(other.gameObject))
{
attackers.Add(other.gameObject);
Debug.Log(attackers[1]);
}
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag.Contains("Enemy"))
{
if (attackers.Contains(other.gameObject))
{
Debug.Log(other.gameObject);
attackers.Remove(other.gameObject);
targeting.text = (" No target");
}
}
}
//begins targeting proccess
void targetselectingstart()
{
if (Input.GetKeyDown(KeyCode.Z))
{
Debug.Log("tar");
howmanyplayers -= 1;
targeting.text = attackers[howmanyplayers].gameObject.name;
playertarget = attackers[howmanyplayers].gameObject;
player.GetComponent<Regularmovement>().enabled = false;
player.GetComponent<combatmovement>().enabled = true;
anim.SetBool("combat", true);
lookattarget = true;
if (howmanyplayers < -1)
{
howmanyplayers = attackers.Count;
}
cameraturnon = true;
}
}
void targetcycle()
{
if (Input.GetKeyDown(KeyCode.X))
{
howmanyplayers += 1;
targeting.text = attackers[howmanyplayers].gameObject.name;
playertarget = attackers[howmanyplayers].gameObject;
player.GetComponent<Regularmovement>().enabled = false;
player.GetComponent<combatmovement>().enabled = true;
anim.SetBool("combat", true);
lookattarget = true;
if (howmanyplayers > attackers.Count)
{
howmanyplayers = 0;
cameraturnon = true;
}
}
}
void lookingattarget()
{
if (lookattarget == true)
{
player.transform.LookAt(playertarget.transform);
}
}
void playerlistcannotbezero()
{
if (howmanyplayers <= 0)
{
howmanyplayers = attackers.Count;
}
}
void playerlistcannotbemax()
{
if (howmanyplayers > attackers.Count)
{
howmanyplayers -= attackers.Count;
}
}
void noenemys()
{
if (attackers.Count == 0)
{
cameraturnon = false;
}
}
// Use this for initialization
void Start () {
if (!isLocalPlayer)
{
return;
}
playertarget = null;
}
// Update is called once per frame
void Update () {
if (!isLocalPlayer)
{
return;
}
lookingattarget();
noenemys();
playerlistcannotbezero();
playerlistcannotbemax();
targetselectingstart();
targetcycle();
}
}